简体   繁体   English

C#Process。从另一个在Windows 8/10中不工作的用户开始

[英]C# Process.Start with another user not working in Windows 8/10

I have program where i start USMT (load or scanstate) with a domain user that gives administrative privileges on the local computer. 我有一个程序,其中我使用域用户启动USMT(加载或scanstate),该用户在本地计算机上提供管理特权。 This is working perfectly fine in Windows 7. 这在Windows 7中运行正常。

The program needs to start as a non administrator user, but executing load/scanstate with administrator privileges. 该程序需要以非管理员用户身份启动,但需要以管理员权限执行加载/扫描状态。

However it fails when running load/scanstate properly becouse its not elevated currectly. 但是,由于无法正确提升负载/扫描状态,因此无法正常运行。 But how can i overcome this, without having administrative rights? 但是,如果没有管理权限,我该如何克服呢?

Best Regards Thomas Nissen 最好的问候托马斯·尼森

        ProcessStartInfo restoreProcessInfo = new ProcessStartInfo
        {
            Verb = "runas",
            UseShellExecute = false,
            Domain = strAdminDomain,
            UserName = strAdminUsername,
            Password = strAdminPassword,
            FileName = loadstate.exe",
            Arguments = "blablabla"
        }

As far as I am aware, the "runas" Verb (any Verb, really) is only respected when UseShellExecute is set to true. 据我所知,仅当UseShellExecute设置为true时才尊重“ runas”动词(实际上是任何动词)。 Try setting UseShellExecute to true while hiding the shell window using the WindowStyle property instead. 尝试将UseShellExecute设置为true,同时使用WindowStyle属性隐藏外壳窗口。

This will, however, prevent you from capturing input and output streams from the process. 但是,这将阻止您捕获过程中的输入和输出流。 Is that something you are interested in doing? 这是您感兴趣的事情吗?

you can impersonate the user. 您可以冒充用户。 Impersonation is the ability of a thread to execute using different security information than the process that owns the thread. 模拟是线程使用与拥有线程的进程不同的安全性信息执行的能力。

Check this thread for how to implement impersonation. 检查线程以了解如何实现模拟。 So the process will be initially executed with windows domain user's privilege and logic that's is placed within the impersonation block will be executed with with impersonated user's privilege. 因此,该过程将首先以Windows域用户的特权执行,并且放置在模拟块中的逻辑将以模拟用户的特权执行。

//Code outside the impersonation block will be executed with current user privilege

Using(Impersonator impersonator = new Impersonator())
{
  //Code written within this block will be executed with elevated(impersonated) user privilege.
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM