gpt4 book ai didi

windows - CreateProcessWithLogonW() 问题 - 需要使用同一用户启动子流程

转载 作者:可可西里 更新时间:2023-11-01 11:41:29 25 4
gpt4 key购买 nike

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

这工作正常,并且该过程按预期开始。但是,当此进程尝试自行启动其他进程时,目前仅使用 CreateProcess(),这些进程启动后立即消失 - 它们是需要桌面访问的可执行文件。

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

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

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

有人知道解决这个问题的方法吗?我在网上的其他地方看到过这个问题,但没有任何明确的解决方案。似乎我可能需要我在 CreateProcessWithLogonW() 中登录的用户的 token ,这样我以后可以用它来启动其他进程?但我无法获得此 token ,是否可以通过任何方式为当前用户取回此 token ?

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

最佳答案

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

/////////////////////////////////////////////////////////////
// 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,以产生我们需要的结果。

关于windows - CreateProcessWithLogonW() 问题 - 需要使用同一用户启动子流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/595176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com