[英]How to start a Console App as running under the System Windows user account?
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
?我将不得不使用
CreateProcessAsUser
吗? How can I get the appropriate parameters to pass to that method?如何获取适当的参数以传递给该方法?
The System accounts password is maintained interally by Windows (I think) ie 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:然而,我确实找到了一个论坛帖子,其中描述了一个巧妙的技巧,可用于通过(ab)使用 windows 服务在系统帐户下运行进程:
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
开关在系统帐户下运行进程。
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如果您想以高权限(它是管理员组的成员)运行您的进程,用户名应该是
LocalSystem
或正常权限的LocalService
EDIT: My mistake LocalSystem & LocalService are not regulary users and, therefore, they cannot be provided as a username.编辑:我的错误 LocalSystem 和 LocalService 不是普通用户,因此,它们不能作为用户名提供。 Kragen's solution is the right one
Kragen 的解决方案是正确的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.