问题
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