启动新进程时绕过提升 [英] Bypassing elevation when launching a new process
问题描述
好的,这是我的问题:我正在尝试启动第三方应用程序.此应用程序显然配置为需要提升,大概是通过嵌入式清单.我的程序在非管理用户的上下文中运行,我希望第三方应用程序在相同的上下文中运行.
OK, here's my problem: I'm trying to launch a third-party application. This application is apparently configured to require elevation, presumably via an embedded manifest. My program is running in the context of a non-administrative user, and I want the third-party application to run in the same context.
当我调用 CreateProcess 时,它返回错误代码 740,请求的操作需要提升."
When I call CreateProcess it returns error code 740, "The requested operation requires elevation."
我尝试了 CREATE_PRESERVE_CODE_AUTHZ_LEVEL 标志,听起来很相关,但没有任何区别.
I've tried the CREATE_PRESERVE_CODE_AUTHZ_LEVEL flag which sounded relevant but it made no difference.
第三方应用程序确实可以在没有管理员权限的情况下运行,例如,如果我禁用了 UAC,然后以非管理员身份运行它.
The third party application does work without administrator privilege, e.g., if I disable UAC and then run it as a non-administrator.
预先感谢您提供的任何提示/想法.
Thanks in advance for any tips/ideas you may have.
推荐答案
将您的流程的环境变量 __compat_layer 设置为 RunAsInvoker.如果设置了这个环境变量,CreateProcess 就会成功.
Set the environment variable __compat_layer for your process to RunAsInvoker. If this environment variable is set, CreateProcess will succeed.
您可以使用 用于此目的的 SetEnvironmentVariable 函数.
这篇关于启动新进程时绕过提升的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!