Is there command to use on windows from java to make the computer sleep?
A:
No. You'd need to execute a separate binary via Runtime.exec()
.
This article suggests
rundll32 Powrprof.dll,SetSuspendState
but I've not tried it.
Brian Agnew
2009-09-02 17:46:25
A:
You may want to look at the OnNow/ACPI Support here.
There is also an old SO post that talks about it here. Probably the reverse of what you want. Might give you some clues though.
Kevin Boyd
2009-09-02 17:47:08
+3
A:
You can do it by executing a shell command, if you java app has enough rights to do so. The command is...
Runtime.getRuntime().exec("Rundll32.exe powrprof.dll,SetSuspendState Sleep");
That and other commands are shown here.
Jherico
2009-09-02 17:48:22
even though the OP accepted this as the answer, future readers should look at http://stackoverflow.com/questions/1369122/sleep-windows-from-java/1369832#1369832 also.
Trevor Harrison
2009-09-03 15:11:19
+1
A:
Anyone suggesting rundll32 should be shot, very few functions are designed to be called by rundll32 and SetSuspendState is not one of them. You will get random behavior (Hibernate vs Standby and Forced vs not forced etc) See this blog entry for more details.
Anders
2009-09-02 20:05:28
why the hate for this answer? seems thoughtful and helpful. At least comment when you -1.
Trevor Harrison
2009-09-02 20:12:23
OK. So the RunDLL32 process ends up with a corrupted stack after calling the function. Who cares? It can't 'infect' the parent process and by the time it occurs the function has already been called.
Jherico
2009-09-02 20:55:20
@Jherico: no, that's not the problem, the problem is, you will be calling SetSuspendState with UNKNOWN arguments, and since SetSuspendState will hibernate OR standby depending on the arguments, that's a bit of a problem
Anders
2009-09-02 21:28:07
@Jherico: Also, if you look at the article you posted, you will notice that they tell you to disable/enable hibernation systemwide to "cure" the unknown/random arguments problem
Anders
2009-09-02 21:32:10