12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using System;
- using System.Security.Principal;
- using System.Windows.Forms;
- namespace TestProject
- {
- static class Program
- {
-
-
-
- [STAThread]
- static void Main()
- {
- try
- {
- WindowsIdentity identity = WindowsIdentity.GetCurrent();
- WindowsPrincipal principal = new WindowsPrincipal(identity);
-
- Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
-
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
-
-
- if (principal.IsInRole(WindowsBuiltInRole.Administrator))
- {
- Application.Run(new Form1());
- }
- else
- {
-
- System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
-
- startInfo.FileName = Application.ExecutablePath;
-
- startInfo.Verb = "runas";
-
- System.Diagnostics.Process.Start(startInfo);
-
- }
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
|