Brunoy
asked on
Change PowerScheme/ Power profile in Windows XP and Windows 7 programming with Delphi 6
Hello,
I am developping a delphi application (borland delphi 6).
My application is a windows service. I launch a cmd/bat file for doing this:
powercfg.exe /create myenergy
powercfg.exe /change myenergy /monitor-timeout-ac %1
powercfg.exe /change myenergy /monitor-timeout-dc %2
powercfg.exe /change myenergy /disk-timeout-ac %3
powercfg.exe /change myenergy /disk-timeout-dc %4
powercfg.exe /change myenergy /standby-timeout-ac %5
powercfg.exe /change upvenergy /standby-timeout-dc %6
powercfg.exe /hibernate on
powercfg.exe /change myenergy /hibernate-timeout-ac %7
powercfg.exe /change myenergy /hibernate-timeout-dc %8
powercfg.exe /setactive myenergy
This configuration is applied to computer without problems when I run it as a bat/cmd script from system prompt (cmd.exe), but when my service is running and launch the batch file in background, it doesn't nothing.
I launch:
cmd /c "c:\myapplication\script.c md 10 5 20 10 15 10 25 20". If I launch "calc.exe", the process appears loaded into memory (in background, I can't interact with it).
I know that in Windows XP and Windows 2000 is possible invoke pwrprof.dll library functions:
GetActivePwrScheme
ReadPwrScheme
WritePwrScheme
...
Documentation: http://msdn.microsoft.com/en-us/library/aa373163%28v=VS.85%29.aspx
In Windows SDK for Vista and Windows 7, the funcions are others.
But I don't know how use these routines for creating a new user power profile. I need fix monitor timeout, disk timeout, standby timeout and suspend timeout for each user log in system.
The experts-exchange site contains code for hibernating computer, but I haven't found examples for changing power scheme of logged user (I need the all right code for both systems: XP and Vista/Windows 7
operating systems).
Thank you very much.
I am developping a delphi application (borland delphi 6).
My application is a windows service. I launch a cmd/bat file for doing this:
powercfg.exe /create myenergy
powercfg.exe /change myenergy /monitor-timeout-ac %1
powercfg.exe /change myenergy /monitor-timeout-dc %2
powercfg.exe /change myenergy /disk-timeout-ac %3
powercfg.exe /change myenergy /disk-timeout-dc %4
powercfg.exe /change myenergy /standby-timeout-ac %5
powercfg.exe /change upvenergy /standby-timeout-dc %6
powercfg.exe /hibernate on
powercfg.exe /change myenergy /hibernate-timeout-ac %7
powercfg.exe /change myenergy /hibernate-timeout-dc %8
powercfg.exe /setactive myenergy
This configuration is applied to computer without problems when I run it as a bat/cmd script from system prompt (cmd.exe), but when my service is running and launch the batch file in background, it doesn't nothing.
I launch:
cmd /c "c:\myapplication\script.c
I know that in Windows XP and Windows 2000 is possible invoke pwrprof.dll library functions:
GetActivePwrScheme
ReadPwrScheme
WritePwrScheme
...
Documentation: http://msdn.microsoft.com/en-us/library/aa373163%28v=VS.85%29.aspx
In Windows SDK for Vista and Windows 7, the funcions are others.
But I don't know how use these routines for creating a new user power profile. I need fix monitor timeout, disk timeout, standby timeout and suspend timeout for each user log in system.
The experts-exchange site contains code for hibernating computer, but I haven't found examples for changing power scheme of logged user (I need the all right code for both systems: XP and Vista/Windows 7
operating systems).
Thank you very much.
ASKER
I need borland delphi code for changing the hard disk, monitor, suspend and hibernation time.
I prefer resolve the problem without use powercfg.exe because this tool is different in Windows XP and Windows Vista / 7. Theremore Windows 2000 doesn't include it.
My problem is about programming, and access pwrprof.dll.
Thanks in advance.
I prefer resolve the problem without use powercfg.exe because this tool is different in Windows XP and Windows Vista / 7. Theremore Windows 2000 doesn't include it.
My problem is about programming, and access pwrprof.dll.
Thanks in advance.
Did you look into these documents? They all are about programming. I know Delphi is not the most favorite Microsoft language but porting samples should be easy.
Of course you can wait for ready solution. It's your choice.
Of course you can wait for ready solution. It's your choice.
ASKER
Link One: ACPI / Power Management - Architecture and Driver Support
Link Two: Application Power Management Best Practices for Windows Vista
Your links are too generic.
I don't know porting samples to Delphi 6. Theremore, for invocating pwrprof.dll functions is necessary declare constants, types and externals declarations of procedures and functions. I don't know invocating external dlls. I always have created account appplications and no system applications.
Thank you.
Link Two: Application Power Management Best Practices for Windows Vista
Your links are too generic.
I don't know porting samples to Delphi 6. Theremore, for invocating pwrprof.dll functions is necessary declare constants, types and externals declarations of procedures and functions. I don't know invocating external dlls. I always have created account appplications and no system applications.
Thank you.
ASKER
I know now the reason.
My script is all right, but I was changing power scheme / power profile of user that runs my service: LOCAL SYSTEM and no of logged user.
I need launch my batch as logged user if I want change his power scheme / power profile.
I'm probing CreateProcessAsUser function, but I am not getting a solution.
The best solution is programming a new power scheme with Windows API and not launching a batch file. So, my question will be open.
But, if I want change power profile of user, I need impersonate him. Naturally I haven´t his password.
This problem is opened as other question.
Thank you very much.
My script is all right, but I was changing power scheme / power profile of user that runs my service: LOCAL SYSTEM and no of logged user.
I need launch my batch as logged user if I want change his power scheme / power profile.
I'm probing CreateProcessAsUser function, but I am not getting a solution.
The best solution is programming a new power scheme with Windows API and not launching a batch file. So, my question will be open.
But, if I want change power profile of user, I need impersonate him. Naturally I haven´t his password.
This problem is opened as other question.
Thank you very much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Especially http://www.microsoft.com/whdc/system/pnppwr/powermgmt/PM_apps.mspx looks like written for you.