gpt4 book ai didi

c++ - 如何检测是否有任何过程阻止Windows进入休眠状态?

转载 作者:行者123 更新时间:2023-12-03 06:55:18 45 4
gpt4 key购买 nike

我想检查是否有任何进程/应用程序使用任何方法使Windows系统保持清醒状态。
我发现有一个API SetThreadExecutionState 可以做到这一点。
https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate
即使我找到了这种API,我仍然找不到找到状态的方法。
我认为视频播放器将使用SetThreadExecutionState暂时保持系统唤醒。但是文件还说

Applications such as word processors, spreadsheets, browsers, andgames do not need to call SetThreadExecutionState.



作为Windows服务,我想确定它们是否将状态设置为ON,或者不包括不需要调用SetThreadExecutionState的应用程序。

最佳答案

The simplest way for me is to detect if there is any application use"certain" API to tell OS that don't sleep now even there is no userinput.


这实际上不是一个非常简单的方法, detours可以做到这一点,但前提是您需要花费大量时间来学习如何使用它。

Detours is a software package for monitoring and instrumenting APIcalls on Windows. Detours has been used by many ISVs and is also usedby product teams at Microsoft. Detours is now available under astandard open source license (MIT). This simplifies licensing forprogrammers using Detours and allows the community to support Detoursusing open source tools and processes.


它以源代码形式分发: https://github.com/microsoft/Detours
有关的:
  • Monitoring or disabling WinAPI functions
  • (Windows) Monitoring API calls in C
  • 关于c++ - 如何检测是否有任何过程阻止Windows进入休眠状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63878482/

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