6

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.

Community
  • 1
  • 1
Marc
  • 9,012
  • 13
  • 57
  • 72

3 Answers3

10

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.

Community
  • 1
  • 1
Marc
  • 9,012
  • 13
  • 57
  • 72
  • problem is that XP SP3's Runas dialog has running as the current user ticked by default, and even ticks "protect my computer and data from unauthorized program activity" - this actually reduces privileges! – eug Feb 23 '14 at 04:45
  • @eug : quite an old topic but I have the same problem today under Windows XP. Remove 'processStartInfo.Verb = "runas";' But keep it for Windows 7+ (not checked under Vista) – Nolmë Informatique Aug 29 '18 at 13:22
3

Windows XP does not have UAC.

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

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
3

You can use the runas command.

Oded
  • 489,969
  • 99
  • 883
  • 1,009