
问题描述:
怎旁亩样用JAVA语言的代码使DOWS系统在规定的丛枝时间关机???
解析:
只知道xp系统可以用shutdown -s
用java的话
Runtime ce = Runtime.getRuntime()
ce.exec("shutdown -s -t timing")
import java.util.*import java.io.*
class Shutdown
{
public static void main(String[] args)
{
System.out.println("Shutdown in 10s")
try{
Runtime.getRuntime().exec("cmd /c Shutdown -t 10")
}catch(IOException e){}
}
}
上面这个程序实现你所说的定时10秒关机
至于定乎行时开机...你告诉我怎么在关机的渣顷坦状态下执行我的程序,我就把开机的程如桐序给你写出来.
哈哈,这个我正好可以帮你,以前写了类似程序开机运行:String regKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\闷悔\Microsoft\蚂梁正\渣陵Windows\\CurrentVersion\\Run"
String myAppName = "DaKa"
try {
Runtime.getRuntime().exec("reg " + (isStart ? "add " : "delete ") + regKey + " "
+ myAppName + (isStart ? " /t reg_sz /d " + dirpath : " /f"))
dirpath是你当前文件的绝对路径(包括文件名)
关机:Runtime.getRuntime().exec("shutdown -s -f -t 10")
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)