Friday, 5 September 2014

Turn off PC with Java Program

Structure of the problem Requirements 

In this problem we will learn how to Turn off PC with Java program. For this program we used the Java Runtime class, through runtime class we can interact with the system in which Java application is running. In this program we warn with simple message and after this asked user to enter time in seconds to turn off the system. Then pass this user value to runtime function as a arguments and your work is done :) . Here is the source code of this interesting program which help you in better understanding.

Source Code

import java.util.Scanner;

public class Turn_Off_Pc{

public static void main(String[] args) throws IOException {

Runtime runtime = Runtime.getRuntime();
BufferedReader br=new BufferedReader(new InputStreamReader(;
System.out.println(" \t \t \t Warning ! Save Your Work Before Run the Code");
System.out.println("Enter the Seconds to Turn off System :");
long seconds =Long.parseLong(br.readLine());
Process proc = runtime.exec("shutdown -s -t "+seconds);

Output of the Program

Turn off PC with Java Program
Turn off PC with Java Program

Turn off PC with Java Program
Turn off PC with Java Program

Share it Please

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

2 comments: Post Yours! Read Comment Policy!▼
Important Note:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

  1. Is this working on Linux and Mac Operating System .. ???