How to make .exe file programmatically set to run as admin always in vista?

爷,独闯天下 提交于 2020-01-07 08:20:30

问题


I have written a winform application in C#. When I run the program for some functionality it required admin permission. After Installation If I set the .exe file to run as admin manually (by clicking right mouse button on .exe file) then my program run perfectly.

Now I need user not to set the run as admin property after installation by clicking right mouse button. I need to set this programaticaly somewhere in the code that user no need to bother about this. This specific problem is only arise for Windows Vista. Can anyone help me out?


回答1:


You need to add a manifest to the app that specifies it require admin privileges. Read more on MSDN.

Update: You can add a manifest to your project by right-clicking on the project and selecting Add / New Item / Application Manifest File. This will add a new file called app.manifest to your project and will reference it from the project properties, in the Manifest dropdown on the Application tab. The default manifest template even has a nice comments on how exactly to change the required UAC execution level.




回答2:


You need to specify the requestedExecutionLevel in the manifest.

See here for a detailed explanation: http://petesbloggerama.blogspot.com/2007/04/making-your-assembly-run-as.html



来源:https://stackoverflow.com/questions/3446211/how-to-make-exe-file-programmatically-set-to-run-as-admin-always-in-vista

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!