Shutdown/Restart Windows With Simple Java Program
We can just make use of the Runtime class in java to execute the shutdown command using the simple java code.
We can shutdown from the command prompt itself.
To know the various ways to shutdown windows take a look at the below video.
Program : (Shut Down)
public class ShutDownMySystem
{
public static void main(String[] args)
{
Runtime runtime=Runtime.getRuntime();
try
{
System.out.println("shutting down ....");
runtime.exec("shutdown /s /t 0");
}
catch (Exception e)
{
System.out.println(e);
}
}
}
Program : (Restart)
public class RestartMySystem
{
public static void main(String[] args)
{
Runtime runtime=Runtime.getRuntime();
try
{
System.out.println("shutting down ....");
runtime.exec("shutdown /r");
}
catch (Exception e)
{
System.out.println(e);
}
}
}
Explanation:
/s - to shutdown
/t - to specify the time in seconds after to shutdown
/r - to restart
Output :
Take a look at the below video to see the the real time output.
With that being said, I am very excited to meet the head of banks, Fintech and crypto investors who dream of disrupting the Fintech arena.
ReplyDeleteIf you are one of those individuals, let’s explore ideas together.
Ankit Jain - Join me on my journey to disrupt the Fintech field and create a frictionless banking experience for upcoming generations.