How to start a Console App as running under the System Windows user account?

Jader Dias picture Jader Dias · Jul 13, 2011 · Viewed 8.9k times · Source

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?

Answer

Justin picture Justin · Jul 13, 2011

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.