[英]CreateProcessAsUser hToken is zero
I'm creating an app (name AppRunner) that will run an executable (name EXE) using winapi.我正在创建一个应用程序(名称 AppRunner),它将使用 winapi 运行可执行文件(名称 EXE)。
In AppRunner, I'm using CreateProcessAsUser in order to run EXE, and this method takes an hToken (a user token).在 AppRunner 中,我使用 CreateProcessAsUser 来运行 EXE,并且此方法需要一个 hToken(用户令牌)。
When AppRunner will be executed by user System in session 0, It will successfully fetch the user token (WTSQueryUserToken with the console session id) and everything will work fine.当 AppRunner 将由 session 0 中的用户系统执行时,它将成功获取用户令牌(带有控制台 session id 的 WTSQueryUserToken),一切都会正常工作。
However, when AppRunner will be executed by the logged in user in session>0, It will not be able to get the user token.但是,当 AppRunner 将由 session>0 中的登录用户执行时,将无法获取用户令牌。
I noticed that when calling CreateProcessAsUser with hToken=0, EXE is being executed under the logged in user in the user's session (>0).我注意到,当使用 hToken=0 调用 CreateProcessAsUser 时,EXE 正在用户 session (>0) 中的登录用户下执行。
Can I assume that calling CreateProcessAsUser with hToken = 0 will execute EXE under the logged in user in the user's session ?我可以假设使用 hToken = 0 调用 CreateProcessAsUser 将在用户的 session 中的登录用户下执行 EXE吗? I didn't find any documentation about it in the CreateProcessAsUser page.
我在 CreateProcessAsUser 页面中没有找到任何关于它的文档。
Thanks谢谢
BTW, in case anyone else encounter this: CreateProcessAsUser with hToken=0 will indeed create a process with the same user as the user of the current process, BUT, CreateEnvironmentBlock will create an environment with default values, which means that appdata folder for example will point to the default user and not the current user's appdata folder.
顺便说一句,万一其他人遇到这种情况:使用 hToken=0 的 CreateProcessAsUser 确实会创建一个与当前进程的用户具有相同用户的进程,但是 CreateEnvironmentBlock 将创建一个具有默认值的环境,这意味着例如 appdata 文件夹将指向默认用户,而不是当前用户的 appdata 文件夹。 This is a big issue for me
这对我来说是个大问题
Two workarounds:两种解决方法:
CreateEnvironmentBlock
.CreateEnvironmentBlock
时继承父进程的 (AppRunner) 环境。 Then APPDATA
environment variable will point to the current user's appdata folder.APPDATA
环境变量将指向当前用户的 appdata 文件夹。 But USERPROFILE
still point to C:\Users\Default
.USERPROFILE
仍然指向C:\Users\Default
。GetCurrentProcessToken
, then pass this token to CreateEnvironmentBlock
.GetCurrentProcessToken
获取父进程的 (AppRunner) 令牌,然后将此令牌传递给CreateEnvironmentBlock
。 Then APPDATA
and USERPROFILE
environment variable both point to current user.APPDATA
和USERPROFILE
环境变量都指向当前用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.