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.
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:
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
Thank you very much.