Search code examples
c#wpfadmin-rights

Request admin right for app for some operation(no full time admin rights)


I want to run application usually with normal rights but for some operations(Managing file associations for example) request admin rights.

Is it possible?

P.S. I know about manifest and requestedExecutionLevel but this is not a good solution. I want aplication have admin rights for some period of time not always.


Solution

  • That is not possible unless you start a new process.

    You can do that with:

    var psi = new ProcessStartInfo();
    psi.FileName = @"yourExe";
    psi.Verb = "runas";
    
    Process.Start(psi);
    

    You could start the same application as you are currently running and pass a switch parameter so the problem knows it only has to execute a specific action.