gpt4 book ai didi

c++ - 我的服务启动的进程上的 OpenProcess/SetProcessAffinityMask

转载 作者:太空宇宙 更新时间:2023-11-04 14:27:55 27 4
gpt4 key购买 nike

在我的 manager.exe 中,我试图更改由我的 service.exe 启动的 worker.exe 的 CPU 使用率。 Service.exe 在系统帐户下运行,而 manager.exe 在登录用户帐户下运行。

当我使用 worker.exe 的 PID 在 manager.exe 中调用 OpenProcess 时,procHandle 为 NULL:

HANDLE procHandle = OpenProcess(PROCESS_SET_INFORMATION, 0, pid);

使用 GetLastError() 我发现我收到了拒绝访问错误。

有什么解决办法吗?我能否以某种方式修改 worker.exe 以授予其他进程对其自身的完全控制权?

最佳答案

您不必调用 OpenProcess

该服务在调用 CreateProcessAsUserCreateProcessWithLogonW 时应该已经拥有对 worker 的完全权限句柄。使用 DuplicateHandle 制作一个适合管理器进程使用的句柄版本,然后让服务将该句柄发送给管理器。服务已经有了管理器的句柄,对吧? DuplicateHandle 需要它。

或者让经理要求服务更改工作进程。

关于c++ - 我的服务启动的进程上的 OpenProcess/SetProcessAffinityMask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2298305/

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