Shutdown/Restart/Logoff/Hibernate system in Java

Shutting down a PC, Java can do it!


A tiny trick to shutdown/restart windows PC after a specific time.


Let's start the timer!


class Shutdown
{
public static void main(String args[]) throws Exception
{
// Create Runtime object
Runtime r=Runtime.getRuntime();

// Shutdown system
r.exec("shutdown -s");

// Restart system
r.exec("shutdown -r");

// Shutdown after specific time (here 60 seconds)
r.exec("shutdown -s -t 60");

// Restart after specific time (here 60 seconds)
r.exec("shutdown -r -t 60");

}
}

I think you're a bit happy now.Fine, you'll have to note that the maximum time that you can make your PC wait for shutdown is 10 years, if you want more than that..... nothing, simply go send a feedback to Microsoft about it, they can do if they wish to, but have a valid reason for the claim ;)

More..

r.exec("shutdown -l"); for logging off, you can also add timer for it, as usual. If you wish to abort system being shutdown then, r.exec("shutdown -a"); this prevents your system from being shutdown.

To turn off PC without warning, then r.exec("shutdown -s -p");

To hibernate a PC, then r.exec("shutdown -h"); you can also use timer for this, not only for this, for any shutdown related operation you want to perform, you can use this option.


No comments: