如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
有些程序功能需要以管理员身份才能运行,以下设置能够让程序在运行过程中取得管理员身份,供参考。方法一在项目工程下添加一个“应用程序清单文件”,默认名为“app.manifest”,将其中“<requestedExecutionLevellevel="asInvoker"uiAccess="false"/>”的level="asInvoker"改为level="requireAdministrator"即可,重新编译生成exe。方法二通过代码实现,在代码中调用所要运行的EXE,设置其权限为管理员:staticvoidMain(string[]Args){/***当前用户是管理员的时候,直接启动应用程序*如果不是管理员,则使用启动对象启动程序,以确保使用管理员身份运行*///获得当前登录的Windows用户标示System.Security.Principal.WindowsIdentityidentity=System.Security.Principal.WindowsIdentity.GetCurrent();//创建Windows用户主题Application.EnableVisualStyles();System.Security.Principal.WindowsPrincipalprincipal=newSystem.Security.Principal.WindowsPrincipal(identity);//判断当前登录用户是否为管理员if(principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)){//如果是管理员,则直接运行Application.EnableVisualStyles();Application.Run(newForm1());}else{//创建启动对象System.Diagnostics.ProcessStartInfostartInfo=newSystem.Diagnostics.ProcessStartInfo();//设置运行文件startInfo.FileName=System.Windows.Forms.Application.ExecutablePath;//设置启动参数startInfo.Arguments=String.Join("",Args);//设置启动动作,确保以管理员身份运行startInfo.Verb="runas";//如果不是管理员,则启动UACSystem.Diagnostics.Process.Start(startInfo);//退出System.Windows.Forms.Application.Exit();}}