使用Java关闭Windows [英] Shutdown Windows with Java

查看:114
本文介绍了使用Java关闭Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Java以编程方式关闭Windows?

Is it possible to shutdown Windows programmatically with Java?

干杯

推荐答案

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

有关关机命令让您的观看愉快

您可能感兴趣的其他一些命令行选项

Some other command line options that may be of interest to you are


-i显示GUI界面,必须是第一个选项

-i Display GUI interface, must be the first option

-l注销(不能与-m选项一起使用)

-l Log off (cannot be used with -m option)

-r关闭并重新启动计算机

-r Shutdown and restart the computer

-m \ computername(远程计算机关机/重启/中止)

-m \computername (Remote computer to shutdown/restart/abort)

-t xx设置关机超时为xx秒

-t xx Set timeout for shutdown to xx seconds

- c评论关机评论(最多127个字符)

-c "comment" Shutdown comment (maximum of 127 characters)






当然,如果你不喜欢这种方法,你可以下载库来实现这一目标。其中一个例子是 Java Windows关机功能

根据他们的SourceForge页面:

According to their SourceForge page:


JWSF - Java Windows Shutdown Functions API允许Java应用程序在大多数窗口上执行以下操作操作系统,关机,重启,注销,锁定工作站。 JWSF使用JNI进行本机调用。 JWSF受LGPL许可证的约束

JWSF - Java Windows Shutdown Functions API allows java applications to perform the following operations on most windows operating system, shutdown, restart, logoff, lock workstation. JWSF makes native calls using JNI. JWSF is subject to the LGPL license

这篇关于使用Java关闭Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆