使用ProcessStartInfo将进程作为本地系统启动

时间:2021-01-30 20:43:20

I am trying to start a process as the LocalSystem account using this code

我正在尝试使用此代码启动一个进程作为LocalSystem帐户

    ProcessStartInfo _startInfo = new ProcessStartInfo(commandName);
_startInfo.UseShellExecute = false;
_startInfo.UserName = @"NT AUTHORITY\SYSTEM";
_startInfo.CreateNoWindow = true;
_startInfo.Arguments = argument;
_startInfo.RedirectStandardOutput = true;

using (Process _p = Process.Start(_startInfo)) {
  _retVal = _p.StandardOutput.ReadToEnd();
  _p.WaitForExit();
}

But I am getting always the same error message saying "Logon failure: unknown user name or bad password". The user calling the function is a local admin and should be able to start a process with local system privilege. I also tried different combination but no luck.

但是我总是会得到相同的错误信息,比如“登录失败:未知用户名或错误密码”。调用该函数的用户是一个本地管理员,应该能够使用本地系统特权启动进程。我也尝试了不同的组合,但没有运气。

I would appreciate any help. Thanks

我希望得到任何帮助。谢谢

2 个解决方案

#1


3  

Unfortunately, I don't think you can do it so simply.

不幸的是,我认为你不能这么简单地做到这一点。

The underlying API that Process.Start() calls accepts a username and password, but since the SYSTEM user isn't a regular user and doesn't have a password I don't believe you can use it with this API.

Process.Start()调用的底层API接受用户名和密码,但是由于系统用户不是普通用户,而且没有密码,我不相信您可以使用这个API。

You would have to use something like psexec (which you can, of course, call from Process.Start()).

您必须使用psexec(当然,您可以从Process.Start()调用它)之类的东西。

#2


0  

I had some difficulties with this a while back. In the end managed it. What you're probably missing is some permission or other. See my previous question/answer.

不久前我在这方面遇到了一些困难。最终成功了。你可能缺少一些许可或其他的。看到我以前的问题/回答。

#1


3  

Unfortunately, I don't think you can do it so simply.

不幸的是,我认为你不能这么简单地做到这一点。

The underlying API that Process.Start() calls accepts a username and password, but since the SYSTEM user isn't a regular user and doesn't have a password I don't believe you can use it with this API.

Process.Start()调用的底层API接受用户名和密码,但是由于系统用户不是普通用户,而且没有密码,我不相信您可以使用这个API。

You would have to use something like psexec (which you can, of course, call from Process.Start()).

您必须使用psexec(当然,您可以从Process.Start()调用它)之类的东西。

#2


0  

I had some difficulties with this a while back. In the end managed it. What you're probably missing is some permission or other. See my previous question/answer.

不久前我在这方面遇到了一些困难。最终成功了。你可能缺少一些许可或其他的。看到我以前的问题/回答。