Sleep Windows with Java
5 answers
Anyone suggesting rundll32 should be shot, there are very few functions designed to call rundll32 and SetSuspendState is n't . You will get random behavior (Hibernate vs Standby and Forced vs not force, etc.). See this blog post for details .
+5
source to share
I currently solved this with https://github.com/twall/jna . Call info http://www.pinvoke.net/default.aspx/powrprof.SetSuspendState
import com.sun.jna.Native;
import com.sun.jna.Platform;
public class WindowsSuspend {
public static native boolean SetSuspendState(boolean hibernate, boolean forceCritical, boolean disableWakeEvent);
static {
if (Platform.isWindows())
Native.register("powrprof");
}
}
Name it instead WindowsSuspend.SetSuspendState(false, false, false)
.
+5
source to share
Not. You will need to execute seperate binary through Runtime.exec()
.
This article suggests
rundll32 Powrprof.dll,SetSuspendState
but I haven't tried it.
0
source to share