5

I tried

var process = new Process
{
    StartInfo = new ProcessStartInfo
    {
        FileName = filename,
        UserName = "System",
        UseShellExecute = false,
    },
};

process.Start();

but it yields

Win32Exception was unhandled

Login failed: unknown user name or wrong password

I will have to use CreateProcessAsUser? How can I get the appropriate parameters to pass to that method?

Jader Dias
  • 88,211
  • 155
  • 421
  • 625

2 Answers2

8

The System accounts password is maintained interally by Windows (I think) i.e. attempting to start a process as the System account by supplying credentials in this way is ultimately destined to failure.

I did however find a forum post that describes a neat trick that can be used to run processes under the system account by (ab)using windows services:

Tip: Run process in system account (sc.exe)

Alternatively the Windows Sysinternals tool PsExec appears to allow you to run a process under the System account by using the -s switch.

Justin
  • 84,773
  • 49
  • 224
  • 367
  • 1
    `psexec -s` is my usual approach. Remember that `psexec` does require an elevated launcher itself. – Richard Jul 13 '11 at 13:47
0

The Username should be LocalSystem if you want to run your process with high privileges (it's a member of Administrators group) or LocalService for normal privileges

EDIT: My mistake LocalSystem & LocalService are not regulary users and, therefore, they cannot be provided as a username. Kragen's solution is the right one

Eugene
  • 2,858
  • 1
  • 26
  • 25