Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run another app as administrator on Windows XP

I used the application manifest file as described here to have a part of my application running with elevated privileges (which it needs).
So when needed, the main program just invokes a small assembly using Process.Start which then handles the task for which admin rights are required.

However, how can I do the same thing on Windows XP?
It seems XP just ignores this manifest and runs the small assembly in the current user context.

like image 913
Marc Avatar asked Jan 17 '11 17:01

Marc


3 Answers

The following code from here does just what I need:

ProcessStartInfo processStartInfo = new ProcessStartInfo("path", "args");
processStartInfo.Verb = "runas";

using (Process process = new Process())
{
   process.StartInfo = processStartInfo;
   process.Start();
   process.WaitForExit();
}

So in fact you need to set "runas" on ProcessStartInfo.Verb. With the attached manifest this code now works fine on Windows XP, Vista and 7.

Update:
See also this answer to a similar question. This is basically the same code, just using arguments as well.

like image 76
Marc Avatar answered Sep 30 '22 04:09

Marc


Windows XP does not have UAC.

You need to call Process.Start with the login credentials of a user with administrative priviliges.

like image 28
SLaks Avatar answered Sep 30 '22 06:09

SLaks


You can use the runas command.

like image 20
Oded Avatar answered Sep 30 '22 05:09

Oded