实现方法
C#
System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
Application.EnableVisualStyles();
System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
else
{
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = System.Windows.Forms.Application.ExecutablePath;
startInfo.Verb = "runas";
System.Diagnostics.Process.Start(startInfo);
System.Windows.Forms.Application.Exit();
}
将这段代码粘贴至Program.cs即可。

执行效果
由于图片丢失,遂找了张网图
