如何在系统Windows用户帐户下启动控制台应用程序?

时间:2022-04-13 16:46:39

I tried

我试着

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

process.Start();

but it yields

但收益率

Win32Exception was unhandled

Win32Exception是未处理的

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?

我必须使用CreateProcessAsUser吗?如何获得传递给该方法的适当参数?

2 个解决方案

#1


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.

系统帐户密码是由Windows(我认为)相互维护的(我认为),即试图以这种方式提供凭证来启动一个进程,最终注定要失败。

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:

然而,我在论坛上发现了一篇文章,描述了一种巧妙的技巧,可以使用windows服务(ab)在系统账户下运行进程:

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

提示:在系统帐户中运行进程(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.

另外,Windows Sysinternals工具PsExec似乎允许您使用-s开关在系统帐户下运行一个进程。

#2


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

如果您希望运行具有高特权的进程(它是管理员组的成员)或具有普通特权的LocalService,那么用户名应该是LocalSystem

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

编辑:我的错误LocalSystem和LocalService不是常规用户,因此它们不能作为用户名提供。Kragen的方法是对的

#1


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.

系统帐户密码是由Windows(我认为)相互维护的(我认为),即试图以这种方式提供凭证来启动一个进程,最终注定要失败。

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:

然而,我在论坛上发现了一篇文章,描述了一种巧妙的技巧,可以使用windows服务(ab)在系统账户下运行进程:

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

提示:在系统帐户中运行进程(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.

另外,Windows Sysinternals工具PsExec似乎允许您使用-s开关在系统帐户下运行一个进程。

#2


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

如果您希望运行具有高特权的进程(它是管理员组的成员)或具有普通特权的LocalService,那么用户名应该是LocalSystem

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

编辑:我的错误LocalSystem和LocalService不是常规用户,因此它们不能作为用户名提供。Kragen的方法是对的