惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - 凌点

clr20r3 system.InvalidOperationException 程序终止的几种解决方案 能上Q 不能上网 JavaScript中url 传递参数(特殊字符) apache 多站点配置 C#中使用 SendMessage 向非顶端窗体发送组合键 System.Xml.XmlException: 根级别上的数据无效 XP,WIN7双系统启动问题 VM安装XP注意事项 VC 命令行 捕获输出 make 信息重定向 VC 进度条制件CProgressCtrl 用法笔记 VC List Control控件高级使用 List Control 控件技巧总汇 VC中字符串取子串总结 VC获取硬盘物理序列号 unicode cstring to char* - 凌点 将unicode的 Cstring 复制到粘贴板 VC由进程ID获取窗口句柄 嵌入式Linux操作系统学习规划
如何禁用Windows屏保和电源管理
凌点 · 2009-11-12 · via 博客园 - 凌点

编写诸如监控、多媒体、大规模数据处理之类程序的时候,我们常常需要禁用屏幕保护和电源管理,以确保程序的正常运行。一般来说,可以使用模拟鼠标键盘动作的办法禁用95下的屏幕保护和电源管理,但是同样的方法应用到2000/NT,却常常会无效,这和系统的设置有关系。
运用Windows平台SDK的界面API可以轻松的做到禁用屏幕保护和电源管理,唯一的缺陷是这种方法无法应用到Windows95下的Win32应用程序中。以下,我将介绍具体方法。

使用SystemParametersInfo这个API来实现对系统的一些参数进行设置(包括屏幕保护和电源管理等):
BOOL SystemParametersInfo(
  UINT uiAction,  // system parameter to retrieve or set
  UINT uiParam,   // depends on action to be taken
  PVOID pvParam,  // depends on action to be taken
  UINT fWinIni    // user profile update option
);

以下是禁用屏幕保护的代码:
void DisableScrSaver()
{
 BOOL bScrActive;
 SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &bScrActive, 0);
 if (bScrActive)
 {
  SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0);
 } 
}
以下是启用屏幕保护的代码:
void CNetRGCltDlg::EnableScrSaver()
{
 SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, TRUE, NULL, 0);
}

由于禁用电源保护不可以在Win95下被Win32应用程序使用,所以要事先判断当前操作系统是不是Win95,这里假设已经用函数BOOL IsWin95()实现。
以下是禁用电源保护的代码:
void DisablePmmSaver()
{
 //
 // 由于电源管理的特殊性,不能直接用SPI_SETLOWPOWERACTIVE命令字实现,而是要设置延时。
 //

 SystemParametersInfo(SPI_GETLOWPOWERTIMEOUT, 0, &m_nLowpowerTimeout, 0);
 SystemParametersInfo(SPI_GETPOWEROFFTIMEOUT, 0, &m_nPoweroffTimeout, 0);
 SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, 0, NULL, 0);
 SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, 0, NULL, 0);
}

以下是启用电源保护的代码
void EnablePmmSaver()
{
 SystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, m_nLowpowerTimeout, NULL, 0);
 SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, m_nPoweroffTimeout, NULL, 0);
 
 m_nLowpowerTimeout = 0;
 m_nPoweroffTimeout = 0;
}

说明:
1 m_nLowpowerTimeout和m_nPoweroffTimeout是用来存储原先延时的变量,当恢复电源保护时要把电源保护延时设置回原来的值;
2 上面的代码仅仅为了说明调用序列,实际应用时还要加上相当多的错误处理代码,这里忽略。