|
Java |
It changes the power options to make the PC go to hibernate one minute after the user logs off.
If you copy and paste this part of the code into a dos window you will see the change in Windows power options
Code
POWERCFG /CHANGE /hibernate-timeout-dc 1It works OK when I install the app and then log off. But if I log
back on and log off after that it gives me "the application was unable
to start" error and an error code.
I can only log off once for it to work. Restarting doesn't fix it.
Would appreciate any help, thanks.

Sam HobbsRank #108 · 20.5K reputationPosted Jan 18, 2011, 5:02 PM EST
Peter Malone11 reputationPosted Jan 18, 2011, 10:44 PM EST
Edit:
I have since changed the code to the following:
string CommandLineString = @"/c POWERCFG /CHANGE /hibernate-timeout-dc 1"; System.Diagnostics.ProcessStartInfo myInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe", CommandLineString); myInfo.CreateNoWindow = true; System.Diagnostics.Process.Start(myInfo); //wait 5 seconds for this to finish System.Threading.Thread.Sleep(5000);"The application was unable to start correctly (0xc0000142). Click OK to close the application."
Suthish NairRank #92 · 22.8K reputationPosted Jan 19, 2011, 1:28 AM EST
Lock, Logoff, Reboot, Shutdown, Hibernate, Standby in .Net
Peter Malone11 reputationPosted Jan 19, 2011, 4:04 AM EST
Sam HobbsRank #108 · 20.5K reputationPosted Jan 19, 2011, 10:27 AM EST
If you need to write a program that works when the user is logged off then you might not be able to use C#. Are you sure that applications can execute without a user being logged on? If not then perhaps you need to write a Windows Service (not a web service).