C#以管理员身份运行程序
2014-11-28 14:12
671 查看
代码:
View Code
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace MyWebBrowser { static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { //获得当前登录的Windows用户标示 System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent(); System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity); //判断当前登录用户是否为管理员 if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) { //如果是管理员,则直接运行 Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } else { //创建启动对象 System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); //设置运行文件 startInfo.FileName = System.Windows.Forms.Application.ExecutablePath; //设置启动动作,确保以管理员身份运行 startInfo.Verb = "runas"; //如果不是管理员,则启动UAC System.Diagnostics.Process.Start(startInfo); //退出 System.Windows.Forms.Application.Exit(); } } } }
View Code
相关文章推荐
- C#默认以管理员身份运行程序
- C#判断程序是否以管理员身份运行,否则以管理员身份重新打开 --转载
- c#程序以管理员身份运行
- C# WinForm判断程序是否以管理员身份运行,UAC权限的提权与降权
- C#默认以管理员身份运行程序
- C#默认以管理员身份运行程序
- 在Windows7上用C#判断程序是否以管理员身份运行
- C#程序如何以管理员身份运行
- C#默认以管理员身份运行程序
- C# 让程序自动以管理员身份运行
- c# 程序以管理员身份运行
- C# 让程序自动以管理员身份运行
- C#默认以管理员身份运行程序
- C# WinForm判断程序是否以管理员身份运行
- C# 让程序自动以管理员身份运行
- C# 让程序自动以管理员身份运行
- C# 让程序自动以管理员身份运行
- 在VS.net(C#)里,设置程序在启动时默认"以管理员身份运行"的方法
- <转载>C# 让程序自动以管理员身份运行
- C# 让程序自动以管理员身份运行