如何以编程方式更改Windows的电源选项中的某些值? [英] How change programmatically some values in power options of Windows?

查看:62
本文介绍了如何以编程方式更改Windows的电源选项中的某些值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各位大家好!



我有一些目标,其中一些:

-enable / disable screensaver mode

-enable /禁用硬盘睡眠模式

-enable / disable关闭显示器

-enable / disable睡眠模式



我'googlin''将近3天!并找到了一小部分信息,这对我没有帮助。



我试图通过注册表更改此设置但是没有成功,因为我不是拥有管理员权限,我得到了ACCESS_DENIED。



我找到了电源管理API,但我不确定如何使用它。 MSDN没有充分的信息。

- 我已经使用SetThreadExecutionState和SystemParametersInfo来保护屏幕,但这些解决方案效果不好。首先我不能确定它是启用还是禁用,其次是bug。

- 我试图使用Registry,但我的应用程序没有管理员。许可,我为什么得到

ACCESS_DENIED

- 我找到了电源管理API。我不知道怎么用它。特别是PowerWritePossibleValue。

给我一些使用这个api的例子。



我正确的方法吗?怎样才能使用Power Management API任务?

如果你知道其他解决方案请写信给我



非常感谢



PS:我搜索了所有MSDN不是完整的信息和良好的链接



奖金问题:

我''我的应用程序可以更改操作系统的选项

本身(例如:在选项中,关闭显示10分钟,以编程方式我可以更改从不)?

Hello everybody!

I have some goals, some of those:
-enable/disable screensaver mode
-enable/disable sleep mode of HDD
-enable/disable turn off display
-enable/disable sleep mode

I''am googlin'' almost 3 days! and found a small part of info, that didn''t help me.

I tried to change this settings through Registry but it was unsuccessful because I don''t have administrator permission, I got ACCESS_DENIED.

I found Power management API, but I am not sure how use it. MSDN is not full of information.
--I have used SetThreadExecutionState and SystemParametersInfo for Screen saver, but those solutions works bad. First I can''t be sure is it enable or disabled, second with bug.
--I tried to use Registry, but my application without admin. permission, taht''s why I got
ACCESS_DENIED
--I found Power Management API. I don''t know how use it. Especially PowerWritePossibleValue.
Provide me some examples to use this api.

Am I on correct way?How can use Power Management API for my tasks?
Please write me if you know another solutions

Thanks a lot

P.S: I searched all MSDN is not full info and a lot of links in goodgle

Bonus question:
I''m a student and newer in programming is it good that my application can change options of OS
itself (for example: In options, turn off display for 10 minutes, programmatically I can change on Never)?

推荐答案

//我试图通过注册表更改此设置

//但它没有成功,因为我没有管理员权限,我得到ACCESS_DENIED。



作为一种可能的解决方案,

你可以编写一个由SYSTEM启动的服务

然后让你的应用与它沟通(为了写一些注册值):)
// I tried to change this settings through Registry
// but it was unsuccessful because I don''t have administrator permission, I got ACCESS_DENIED.

As one possible solution,
you could write a service to be started by SYSTEM
and then let your application communicate with it (order to write some reg-values) :)


这篇关于如何以编程方式更改Windows的电源选项中的某些值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆