Log out using java

How to use java to exit a window. This can be the use of some windows of your own exe through Runtime (), or other methods. It would be more efficient if you could provide a good alternative than using external programs such as 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

+6
source share
3 answers

Do this (-l to log out, -r to reboot, etc.):

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

or (0 to exit the system),

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

You can also make a simple .bat file if it is just the file you want. Open notepad, enter the code below, save as * all the files, name it "logoff.bat" or something else, and it should work.

 shutdown -l 
+2
source

You can call the shutdown executable from the Runtime.getRuntime().exec(...) method. Check out this Q & A question: How to disable reboot - unload Windows via bat file?

+1
source

Source: https://habr.com/ru/post/954437/


All Articles