简体   繁体   English

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

[英]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.

相关问题 在系统帐户下运行 Windows 计划任务时出错 - Error running a Windows Scheduled Task under System Account C#控制台应用程序是否在当前用户帐户下运行? - Does a C# console app run under current user account? 我在“ SYSTEM”帐户下运行的C#代码将如何启动需要提升而不会触发提示的程序? - How would my C# code running under “SYSTEM” account start a program which requires elevation without triggering a prompt? 系统重启 winform 后使用相同的用户帐户启动应用程序 - Start App with Same User Account after System Restart winforms 作为系统帐户运行的 Windows 服务如何获取当前用户的 \AppData\Local\ 特殊文件夹? - How can Windows service running as System account get current user's \AppData\Local\ special-folder? 在带有“本地系统帐户”的“ Windows服务”下运行时,.NET Windows 7截屏不起作用 - .NET Windows 7 take screenshot not working when running under 'Windows Service' with 'Local System Account' 如何终止在特定用户帐户下运行的特定进程 - How to kill specific process running under specific user account 检测应用程序是否在系统帐户下运行? - Detect if application is running under system account? 是否可以使用没有 windows 服务的服务帐户(域)在不同的用户(模拟)下运行代码? - Is running code under a different user (impersonation) possible with a service account (domain) without a windows service? 在C#应用程序中同时执行多个任务,每个任务都在一个单独的Windows用户帐户下 - Executing multiple tasks simultaneously in a C# app, each under a separate Windows user account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM