在Windows 7上启动C#exe而不提示UAC
我有C#可执行文件,我想在Windows 7上启动而没有对话框要求以管理员身份运行..所以这是我的程序内部启动名为testApp.exe的C#可执行文件的代码。
Process testApp = new Process(); testApp.StartInfo.FileName = "C:\\Program Files\\Common Files\\testApp.exe"; testApp.Start();
我也为这两个节目创建了最小的节目。 app.manifest用于testApp.exe和app.manifest,用于启动testApp.exe的程序,然后我将两个清单中的以下行更改为:
requestedExecutionLevel level =“requireAdministrator”uiAccess =“false”
当我双击testApp.exe运行它时,testApp.exe程序崩溃,但是当我以管理员身份运行它时,它运行正常,没有崩溃。 因此,当我运行启动testApp.exe的程序时,此行为也会发生相同的情况,testApp.exe崩溃。
我必须在这里做错事。 我是否需要更改清单的名称,因为我使用visual studio 2010生成的默认名称。
谢谢。
其实你应该只使用
requestedExecutionLevel level =“requireAdministrator”uiAccess =“false”
仅当您想以管理员身份运行时。
将此更改为:
requestedExecutionLevel level =“asInvoker”uiAccess =“false”
你会好起来的。
使用info.Verb =“runas”; //提供以管理员身份运行
我的50美分,
而不是在清单中添加requestedExecutionLevel level="asInvoker" uiAccess="false"
,您可以使用任务计划程序运行几乎任何最高级别的任何内容(管理员模式)
来源: http : //www.liberalcode.com/2014/01/automating-run-as-administrator-from-c.html
虽然上面的post讨论了远程运行它,但你可以轻松地将其更改为在本地运行。