1

I have a process running under the SYSTEM account (can't change this) that needs to execute a series of DOS-style commands. Specifically, it needs to run w32tm /resync which requires administrator privileges.

I have tried using the "runas" verb, which seems to take no effect even with ShellExecute set to true. I have also tried switching to a (known) user on the local machine, but I get the following exception: "The specified service does not exist as an installed service". If I run the program as the user I attempted to switch to, it works fine (admin is set in the app manifest).

I have also tried running each command as a separate process without using the batch file, and that does not seem to help either.

With everything I have tried so far, I either get the aforementioned exception or the call to w32tm /resync fails (indicative of not having admin rights).

Any ideas are appreciated!

Here is the code used to switch users:

procInfo.FileName = scriptPath;
procInfo.UserName = "admin";
procInfo.UseShellExecute = false;
procInfo.CreateNoWindow = true;
Process.Start(procInfo);
Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
  • 2
    possible duplicate of [How to start a Process as administrator mode in C#](http://stackoverflow.com/questions/2532769/how-to-start-a-process-as-administrator-mode-in-c-sharp) – default Feb 26 '14 at 22:57
  • Wait.. maybe not.. I just reread that you already tried the `Verb` property.. (Although, the other answers might help) – default Feb 26 '14 at 22:58
  • I've tried those answers (spent quite a bit of time looking at that question before posting this one). The main problem I'm having seems to be centered around the fact that this process is automatically launched (under the SYSTEM user) rather than the user starting it (which works just fine with my manifest file). – BradleyDotNET Feb 26 '14 at 23:01
  • If it helps, I could narrow the question to just how to successfully run the program as a different user, though I'm really just trying to get it to run as admin. – BradleyDotNET Feb 26 '14 at 23:05
  • here's another solution using `CreateProcessAsUser`: http://stackoverflow.com/a/10122287/238902. It's a bit bulky though – default Feb 26 '14 at 23:08

0 Answers0