<转载>C# 让程序自动以管理员身份运行

在程序中加入MANIFEST资源

打开Vs2005或vs2008工程,看在Properties下是否有app.manifest这个文件;如没有,右击工程在菜单中选择“属性”。

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

  打开app.manifest文件,将

<requestedExecutionLevel level="asInvoker" uiAccess="false"/>

  改为

<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>

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

原文地址:https://www.cnblogs.com/ChangTan/p/2368812.html