c#.exe以管理员身份运行

 
在程序中加入MANIFEST资源文件
首先打开Vs工程,看在Properties下是否有app.manifest这个文件;

 

如没有,右击工程在菜单中选择“Properties”,

 

 
选中"Security",在界面中勾选"启用ClickOnce 安全设置"后,在Properties下就有自动生成app.manifest文件。
打开app.manifest文件,找到如下代码:
<requestedExecutionLevel level="asInvoker" uiAccess="false" />  
将其修改为:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
 
然后在"Security"中再勾去"Enable ClickOnce Security Settings"后,重新编译就可以了。
posted @ 2019-08-24 15:26  Mr_LiangJianan  阅读(852)  评论(0编辑  收藏  举报