[STAThread]
static void Main()
{
#if !DEBUG
if (!IsAdmin())UpAdmin();
#endif
if (Environment.OSVersion.Version.Major >= 6) SetProcessDPIAware();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
private static bool IsAdmin()
{
return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
}
private static void UpAdmin()
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = Application.ExecutablePath;
psi.Verb = "runas";
try
{
Process.Start(psi);
Application.Exit();
Environment.Exit(0);
}
catch (Exception eee)
{
Trace.WriteLine(eee.Message);
}
}
#region Windows 窗体设计器生成的代码
private void InitializeComponent()
{
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
}
#endregion