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

10 comments:

  1. 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

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

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

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

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

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

    -t: seconds to wait before rebooting

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

    -t: seconds to wait before reboot

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

    ReplyDelete