Does somebody know how to get admin privileges AT RUNTIME? Please do not suggest this:
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>
Hope somebody knows how to do that.
I mean, for example, consider this situation: I have an app that runs without administrator rights and usually does not makes any changes on your computer. But if you click one certain button, the app will ask for admin rights and then does something, which is needed.
You can't change the privilege level of a currently running process. You CAN launch a new process, asking for elevated permissions. Process.Start() supports the flag "runas".
using (Process configTool = new Process())
{
configTool.StartInfo.FileName = "foo.exe"
configTool.StartInfo.Arguments = "--bar";
configTool.StartInfo.Verb = "runas";
configTool.Start();
configTool.WaitForExit();
}
See Elevating process privilege programmatically?
You could separate functions of your application into a second executable, or re-launch your application with elevated permissions with "runas".