防止程序执行过程中Windows休眠

Native模式下的程序的函数调用:

ZwSetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED |ES_CONTINUOUS ,&dwRetState);

上层程序:

SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED );

 

Syntax
EXECUTION_STATE WINAPI SetThreadExecutionState(
  __in  EXECUTION_STATE esFlags
);
Parameters
esFlags [in]

The thread's execution requirements. This parameter can be one or more of the following values.

ValueMeaning

ES_AWAYMODE_REQUIRED
0x00000040

Enables away mode. This value must be specified with ES_CONTINUOUS.

Away mode should be used only by media-recording and media-distribution applications that must perform critical background processing on desktop computers while the computer appears to be sleeping. See Remarks.

Windows Server 2003 and Windows XP/2000:  ES_AWAYMODE_REQUIRED is not supported.

ES_CONTINUOUS
0x80000000

Informs the system that the state being set should remain in effect until the next call that uses ES_CONTINUOUS and one of the other state flags is cleared.

ES_DISPLAY_REQUIRED
0x00000002

Forces the display to be on by resetting the display idle timer.

ES_SYSTEM_REQUIRED
0x00000001

Forces the system to be in the working state by resetting the system idle timer.

ES_USER_PRESENT
0x00000004

This value is not supported. If ES_USER_PRESENT is combined with other esFlags values, the call will fail and none of the specified states will be set.

Windows Server 2003 and Windows XP/2000:  Informs the system that a user is present and resets the display and system idle timers. ES_USER_PRESENT must be called with ES_CONTINUOUS.

参见:http://msdn.microsoft.com/zh-cn/library/aa373208(en-us).aspx

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值