如何使用java注销窗口。 它可以通过运行时()或其他方法使用一些Windows自己的exe文件。如果你可以提供一些比使用外部程序如nircmd.exe更好的替代方法。
当我使用这个代码时,
String shutdownCmd = "rundll32.exe shell32.dll,SHExitWindowsEx 0"; Process child = Runtime.getRuntime().exec(shutdownCmd);
我明白了

做到这一点(-l在这里注销,-r为了重启等)。
String shutdownCmd = "shutdown -l" Process child = Runtime.getRuntime().exec(shutdownCmd);
或(这里注销时为0),
String shutdownCmd = "rundll32.exe shell32.dll,SHExitWindowsEx 0" Process child = Runtime.getRuntime().exec(shutdownCmd);
如果它只是一个你想要的文件,你也可以创建一个简单的.bat文件。 打开记事本,键入下面的代码,保存为*所有文件,称之为'logoff.bat'或什么,它应该工作。
shutdown -l
您可以从Runtime.getRuntime().exec(...)方法调用shutdown可执行文件。 看看这个问答有关的详细信息: 如何关机 – 重新启动 – 通过bat文件注销Windows?