在程序中加入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"后,重新編譯就可以了。