Thursday, June 5, 2008

Shutdown Windows using Java

Using JNI for it may be an overkill ...


may try

String command = ""; ( click here for shutdown_command )
Process child = Runtime.getRuntime().exec(command);


Or may be try one of these ...
Try one of these (they've both worked, but there might be problems with one - too long ago, don't remember, though )

C:\WINDOWS\RUNDLL32.EXE SHELL32.DLL,SHExitWindowsEx 1
C:\WINDOWS\RUNDLL32.EXE user,exitwindows

11 comments:

Guru said...

pic and well handled....Lolz

Vaibhav said...

ya best is write the command in a batch file and call the batch file from java. Respect all OS as well. so dont forgot to add:

os.name check

Anonymous said...

You can use JWSF (Java Windows Shutdown Functions) to shutdown,reboot,log-off, and lock any 32bit windows system.

Link: http://jwsf.sourceforge.net/

Anonymous said...

You can use JWSF (Java Windows Shutdown Functions) to shutdown,reboot,log-off, and lock any 32bit windows system.

Link: http://jwsf.sourceforge.net/

Lavnish said...

thanks for the info buddy

elangovv said...

Try the link for best Shutdown help
Click here

Z. Gonzalez said...

Runtime.getRuntime().exec("shutdown -r -t 5");

-t: seconds to wait before rebooting

Z. Gonzalez said...

Runtime.getRuntime().exec("shutdown -r -t 5");

-t: seconds to wait before reboot

Lavnish said...

thanks for the comment

Unknown said...

RUNDLL32.EXE SHELL32.DLL,SHExitWindowsEx 1
works only on win98

Lavnish said...

Thanks for the info