سؤال

I'm working with windows power management APIs (PowrProf.dll P/Invokes) in C# to get and set power management settings of the system, but I'm not sure if the power management settings are user-specific or machine-specific :(

The flow for Windows XP is to get active power scheme (using GetActivePwrScheme()), read global power settings (using ReadGlobalPwrPolicy()), read scheme-specific settings (using ReadPwrScheme()) and if necessary, write the modified data back to system (using SetActivePwrScheme()).

The flow for windows vista and 7 is to get active power scheme (using PowerGetActiveScheme()), read individual power settings (using PowerReadACValueIndex() and PowerReadDCValueIndex()) and if necessary, write the modified data back to system (using PowerWriteACValueIndex() or PowerWriteDCValueIndex()).

The thing is I prefer to run these codes in a windows service and am afraid that if I run these I'll be getting and setting power management settings for the SYSTEM account. I'm a little bit confused, please help.

Thanks in advance.

هل كانت مفيدة؟

المحلول

After hours of searching the Internet, finally I had to settle for the MSDN documentation. According to MSDN for XP we have :

Global User Power Policy : Contains global user power policy settings that apply to all power schemes for a user.

Global Machine Power Policy : Contains global computer power policy settings that apply to all power schemes for all users.

User Power Policy : Contains power policy settings that are unique to each power scheme for a user.

Machine Power Policy : Contains computer power policy settings that are unique to each power scheme on the computer.

And for Vista+, there are no global/local or user/machine settings; instead, everything is scheme specific and the settings apply to all users. (See this)

But when I tested aforementioned facts on two different machines (one running on Win XP and the other running on Win 7), I got unexpected results! On XP, running my code from a windows service (running as SYSTEM account) and a windows app (running as an administrator account) indicated no user-specific behavior. On Win7, the same experiment, created the same results!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top