Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logoff computer using java

How to use java to log off windows. It could be using some windows own exe through Runtime(), or and other methods.It would be more efficient if you could provide some good alternative than using external programs like nircmd.exe .

When I use this code,

String shutdownCmd = "rundll32.exe shell32.dll,SHExitWindowsEx 0";
Process child = Runtime.getRuntime().exec(shutdownCmd);

I get

ERROR MSG

like image 888
meain Avatar asked Sep 23 '13 16:09

meain


2 Answers

Do this (-l for logoff here, -r for restart, etc.):

String shutdownCmd = "shutdown -l";
Process child = Runtime.getRuntime().exec(shutdownCmd);

or (0 for logoff here):

String shutdownCmd = "rundll32.exe shell32.dll,SHExitWindowsEx 0";
Process child = Runtime.getRuntime().exec(shutdownCmd);
like image 110
adi Avatar answered Oct 17 '22 16:10

adi


You can also make a simple .bat file if it's just a file you want. Open notepad, type the code below, save as *all files, call it 'logoff.bat' or something and it should work.

shutdown -l
like image 25
Freek Mencke Avatar answered Oct 17 '22 14:10

Freek Mencke