-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathProgram.cs
78 lines (67 loc) · 2.19 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#define ENABLEMACRO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using TTMulti.Forms;
using TTMulti.Controls;
using System.Xml.Serialization;
using System.IO;
namespace TTMulti
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
if (Environment.OSVersion.Version.Major >= 6)
SetProcessDPIAware();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (Properties.Settings.Default.UpgradeRequired)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.UpgradeRequired = false;
Properties.Settings.Default.Save();
}
if (Properties.Settings.Default.runAsAdministrator)
{
if (args.Length == 0 || args[0] != "--runasadmin")
{
if (TryRunAsAdmin())
{
return;
}
}
}
MulticontrollerWnd mainWindow = new MulticontrollerWnd();
WindowWatcher.Instance.SynchronizingObject = mainWindow;
Application.Run(mainWindow);
}
internal static bool TryRunAsAdmin()
{
ProcessStartInfo processInfo = new ProcessStartInfo(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
processInfo.Arguments = "--runasadmin";
processInfo.UseShellExecute = true;
processInfo.Verb = "runas";
try
{
Process.Start(processInfo);
return true;
}
catch
{
Properties.Settings.Default.runAsAdministrator = false;
Properties.Settings.Default.Save();
return false;
}
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
}
}