Python pywin32 访问被拒绝

发布于 2024-12-21 19:30:17 字数 525 浏览 3 评论 0原文

所以,我尝试使用 pywin32 模块在 python 中编写一个简单的时间跟踪器。大多数情况下它工作正常,但在某些情况下会显示以下错误之一:

(5, 'OpenProcess', 'Access is Denied.')
(87, 'OpenProcess', 'The Parameter is incorrect.)'

最小化窗口或运行全屏应用程序(例如游戏)时通常会出现问题。

以管理员身份运行脚本没有帮助。这就是我尝试做的事情:

windowName = win32gui.GetForegroundWindow()
t, p = win32process.GetWindowThreadProcessId(windowName)
handle = win32api.OpenProcess(0x0410, False, p) 
windowPath = win32process.GetModuleFileNameEx(handle, 0)

有什么方法可以解决这个问题吗?

So, I'm trying to write a simple time tracker in python using the pywin32 module. It works fine most of the time, but in some cases it shows one of the following errors:

(5, 'OpenProcess', 'Access is Denied.')
(87, 'OpenProcess', 'The Parameter is incorrect.)'

The problems usually occur when minimizing a window or running a full screen application such as a game.

Running the script as an administrator does not help. This is how I'm trying to do it:

windowName = win32gui.GetForegroundWindow()
t, p = win32process.GetWindowThreadProcessId(windowName)
handle = win32api.OpenProcess(0x0410, False, p) 
windowPath = win32process.GetModuleFileNameEx(handle, 0)

Any way to fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟─花易冷 2024-12-28 19:30:17

首先,您是否需要0x0410权限(PROCESS_VM_READ+PROCESS_QUERY_INFORMATION)?也许获取 PROCESS_QUERY_INFORMATION 或 PROCESS_QUERY_LIMITED_INFORMATION 足以满足您的需求?检查此 MSDN 页面以获取权限说明 http://msdn.microsoft.com/en-us/library/windows/desktop/ms684880(v=vs.85).aspx

如果仍然如此如果失败,您可以尝试使用 SeDebugPrivilege 为您的进程添加调试权限,并且使用它们它应该打开您想要的任何进程。检查以下链接以获取详细信息:

First of all do you need 0x0410 permissions (PROCESS_VM_READ+PROCESS_QUERY_INFORMATION)? Maybe obtaining PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION is enough for your needs? Check this MSDN page for permissions description http://msdn.microsoft.com/en-us/library/windows/desktop/ms684880(v=vs.85).aspx

If this still fail you can try add Debug permission using SeDebugPrivilege for your process and with them it should open any process you want. Check these links for more info:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文