Reputation: 164
I want my C# program to run with administrator privileges. I know I can do this by editing the manifest file. But is there any possible way to ask the user's permission only once (at first launching of program), not every time?
Upvotes: 0
Views: 1232
Reputation: 10026
Yes, but not directly. You can use the Task Scheduler to create Administration Mode Shortcuts without the UAC Prompts. See this link.
You could probably wire something up programmatically that would create this shortcut upon first run.
Upvotes: 2
Reputation: 612904
No you cannot do that. When running under UAC, if an application needs to be elevated, the UAC dialog must be shown every time the process starts.
If you want to minimise the amount of times the user has to face the UAC dialog, the solution is for your application not to require elevation. If there are some tasks that your application performs that do require elevation, move them into a separate process, and request elevation only when the user attempts those tasks. All these issues are covered in some detail over on MSDN in the UAC guidelines.
Upvotes: 4
Reputation: 564403
But I want to know is there any possible way to ask user's permission only once(at first launching of program), not every time?
No, there is not. The entire purpose of UAC is to make sure the user is aware that they are providing elevated permissions every time they execute a program that requires it. There is no way to make your program "violate" that behavior.
Upvotes: 2