使用ProcessStartInfo以LocalSystem启动进程

auh*_*orn 7 .net c#

我正在尝试使用此代码作为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();
}
Run Code Online (Sandbox Code Playgroud)

但我总是得到相同的错误消息"登录失败:未知用户名或密码错误".调用该函数的用户是本地管理员,应该能够启动具有本地系统特权的进程.我也试过不同的组合,但没有运气.

我将不胜感激任何帮助.谢谢

EMP*_*EMP 3

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

Process.Start() 调用的底层 API 接受用户名和密码,但由于 SYSTEM 用户不是普通用户并且没有密码,我不相信您可以将其与此 API 一起使用。

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