How to shut down a PC using simple java code ?

To shutdown a PC from a java program ,we may use Runtime.getRuntime() & executes a process shutdown (just like from cmd) :

 

CODE :

 

class ShutDownCode
{
public static void main(String a[])
{
try
{
Runtime.getRuntime().exec(“shutdown.exe -s -t 0”);
}catch(Exception e)
{
System.out.println(e);
}
}
}

Above code will shutdown the PC when the program is executed.



 

 

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.