Reputation: 41
I'm write a C# GUI app on VS10. One of its required functions is to check the content of a certain file, and if it needs updating - it must be updated in administrator mode. Writing in the manifest file forces the app to be run in administrator mode regardless of the file content, which is undesirable (just because it's a pain). Is there a way to prompt for administrator mode during the runtime and only if needed? Thanks!
Upvotes: 4
Views: 334
Reputation: 13907
Unfortunately, you can't escalate at runtime.
To accomplish the same goal, separate the code that updates your file into its own executable, which has administrator access through its manifest.
Running this application from your main app allows you to request administrator access when it's necessary without escalating the permissions unnecessarily on the rest of your code.
Upvotes: 4
Reputation: 4849
I believe the solution is for the application to restart itself in administrator mode, if/when required.
A quick google reveals:
But I do agree with @WillEddins' answer... it would be "better" (if possible/practical) to separate out the administrator "mode" code into a different executable. I guess this would depend on (among other things, like effort/cost/benefit/risk) how tightly integrated the admin functions are intermingled with non-admin functions.
Upvotes: 2