【问题标题】:CreateProcessWithLogonW() problems - Need to launch sub-processes with the same userCreateProcessWithLogonW() 问题 - 需要使用同一用户启动子进程
【发布时间】:2009-02-27 15:16:56
【问题描述】:

我有一个 Windows 可执行文件,它是通过使用一组指定的用户详细信息调用 CreateProcessWithLogonW() 从服务中启动的。

这工作正常,进程按预期开始。然而,当这个进程试图自己启动其他进程时,目前只是使用 CreateProcess(),这些进程会立即启动然后立即终止——它们是需要桌面访问权限的可执行文件。

阅读微软关于 CreateProcess() 的文章后 - http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx

我认为可以看出为什么会发生这种情况,并且在一定程度上是有道理的。 CreateProcess() 知道调用进程正在模拟用户,因此它使用它的父进程,在本例中是本地系统帐户。但是当然,在本地系统帐户中运行的任何东西都没有我们需要的访问权限,所以启动的进程就会死掉。

奇怪的是,当我之前使用 LogonUser() 和 CreateProcessAsUser() 在服务中启动初始可执行文件时,它运行良好。但由于没有正确权限的问题,我不得不将其更改为 CreateProcessWithLogonW()。

有人知道这个问题的解决方案吗?我在网上其他地方看到过关于这个的讨论,但没有任何明确的解决方案。似乎我可能需要我在 CreateProcessWithLogonW() 中登录的用户的令牌,以便以后可以使用它来启动其他进程?但是我没有办法获得这个令牌,可以以任何方式为当前用户检索它吗?

任何帮助将不胜感激,谢谢:)

【问题讨论】:

    标签: windows windows-services credentials createprocess


    【解决方案1】:

    我们使用我很久以前找到的一些代码解决了这个问题。其中一个源模块的“版权”部分包含以下内容:

    /////////////////////////////////////////////////////////////
    // CreateProcessAsUser.cpp
    // 
    // Written by Valery Pryamikov (1999)
    // 
    // Command line utility that executes a command under specified user identity 
    // by temporarily installing itself as a service.
    //
    // Based on Keith Brown's AsLocalSystem utility (http://www.develop.com/kbrown)
    // Uses some code from Mike Nelson's dcomperm sample utility 
    //   and from tlist sample (Microsoft Source Code Samples)
    //
    // Use:
    //  CreateProcessAsUser.exe [-i[nteractive]]|[-s[ystem]]|
    //       [-u"UserName" -d"DomainName" -p"Password"]|[-a"AppID"] command
    //  Command must begin with the process (path to the exe file) to launch
    //  -i        process will be launched under credentials of the 
    //            "Interactive User" (retrieved from winlogon\shell process)
    //  -a        process will be launched under credentials of the user 
    //            specified in "RunAs" parameter of AppID.
    //  -s        process will be launched as local system
    //  -u -d -p  process will be launched on the result token of the 
    //            LogonUser(userName,domainName,password,LOGON32_LOGON_BATCH...)
    //
    // either (-s) or (-i) or (-a) or (-u -d -p) parameters must supplied
    // 
    // Examples:
    // CreateProcessAsUser -s cmd.exe
    // CreateProcessAsUser -a"{731A63AF-2990-11D1-B12E-00C04FC2F56F}" winfile.exe
    //
    /////////////////////////////////////////////////////////////
    

    也许这些信息会在您的 Google 搜索中产生命中 - 我尝试了一些快速尝试,但空手而归。 我们将内部分解为一组 API,从而产生我们需要的结果。

    【讨论】:

      【解决方案2】:

      您是否拥有使用CreateProcessWithLogonW 启动的代码(然后又调用CreateProcess)?如果您不这样做,那么您可能需要对其执行 IAT (or API) hooking(即在运行时),以使用同样使用 CreateProcessWithLogonW 的适当过程替换对 CreateProcess 的任何调用或CreateProcessWithTokenW。见APIHijackDetours

      完成此操作后,子进程可能需要访问HKCU。如果您还没有这样做,您应该在调用 CreateProcessWithLogonW 之前加载每个模拟用户的配置文件,每个用户一次。

      默认情况下,CreateProcessWithLogonW 不加载指定用户 配置文件到 HKEY_USERS 注册表 钥匙。这意味着访问 HKEY_CURRENT_USER 中的信息 注册表项可能不会产生结果 符合正常的 交互式登录。这是你的 加载用户的责任 注册表配置单元到 HKEY_USERS 之前 通过调用 CreateProcessWithLogonW 使用 LOGON_WITH_PROFILE,或通过 调用 LoadUserProfile 函数。

      【讨论】:

        【解决方案3】:

        服务是否没有允许它们与桌面交互的选项?如果可以为您的服务设置该选项,那可能是最简单的解决方案。

        【讨论】:

        • 该选项已设置,问题不是服务本身,而是在正确的用户下正常启动可执行文件,是可执行文件尝试启动的进一步进程导致问题...
        • 有趣。我原以为权限会被子进程继承。
        【解决方案4】:

        我假设这个过程是一个服务;问题中未指定,但考虑到它作为本地系统帐户运行,这似乎是合乎逻辑的。

        你卡住的地方不是CreateProcess,而是CreateService。如果您希望您的服务能够与桌面交互,则必须将SERVICE_INTERACTIVE_PROCESS 指定为参数dwServiceType 的标志之一。此设置由服务的子进程继承。

        您还可以使用服务工具修改现有服务的设置,选择服务的属性,单击“登录”选项卡,然后选中“允许服务与桌面交互”复选框。

        【讨论】:

        • 哎呀,我从上面的cmets看到另一个问题,这已经被排除了。
        猜你喜欢
        • 1970-01-01
        • 2013-12-13
        • 2011-10-01
        • 1970-01-01
        • 2011-02-10
        • 1970-01-01
        • 1970-01-01
        • 2022-06-14
        相关资源
        最近更新 更多