C# 让程序默认以管理员运行

来源:互联网 发布:高仿拉勾网 php源码 编辑:程序博客网 时间:2024/05/29 14:37


在程序中加入MANIFEST资源文件

首先打开Vs工程,看在Properties下是否有app.manifest这个文件;

如没有,右击工程在菜单中选择“Properties”,出现界面如下图:

选中"Security",在界面中勾选"Enable ClickOnce Security Settings"后,在Properties下就有自动生成app.manifest文件。

打开app.manifest文件,找到如下代码:

[html] view plaincopy
  1. <requestedExecutionLevel level="asInvoker" uiAccess="false" />  

 将其修改为:

[html] view plaincopy
  1. <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />  

 然后在"Security"中再勾去"Enable ClickOnce Security Settings"后,重新编译就可以了。


若在点击“调试”或“执行”后出现如下窗口,选择“使用其他凭据重新启动”即可。


0 0