【发布时间】:2014-03-06 07:58:36
【问题描述】:
try {
final String REG_ADD_CMD ="cmd /c reg add \"HKEY_LOCAL_MACHINE\\SOFTWARE\\"+
"Microsoft\\Windows\\CurrentVersion\\WindowsUpdate"+
"\\Auto Update\" /v AUOptions /t REG_DWORD /d 1 /f";
Process objProcess;
//objProcess cmd /c = Runtime.getRuntime().exec(new String[]
//{"REG ADD \"", " HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows
//\\CurrentVersion\\WindowsUpdate\\Auto Update"," /v AUOptions /t REG_DWORD /d 1 /f"});
objProcess = Runtime.getRuntime().exec(REG_ADD_CMD);
System.out.println("REG_ADD_CMD:::"+REG_ADD_CMD);
BufferedReader reader=new BufferedReader(new InputStreamReader(objProcess.getInputStream()));
String line=reader.readLine();
System.out.println("Windows auto update::::"+line);
final int exitStatus = objProcess.waitFor();
int exitVal = objProcess.exitValue();
System.out.println("exitStatus::::"+exitStatus);
System.out.println("exitVal::::"+exitVal);
//System.out.println("Processed finished with status: " + exitVal);
if(exitStatus != 0){
System.err.println("Error while installing application!!");
}
//objProcess = Runtime.getRuntime().exec("reg add "HKEY_LOCAL_MACHINE\SOFTWARE\"+
// "Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" /v AUOptions /t REG_DWORD /d 1 /f");
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这是我在 Windows 7 中禁用 Windows 自动更新的代码。一旦我执行,我的控制台中就会收到“操作成功完成”的响应,但它没有反映在控制面板中 有人可以帮忙吗? 谢谢
【问题讨论】:
-
天哪,标题好长!
-
使用 java 在 windows 7 中禁用 windows 自动更新
-
^ 现在这是一个更有趣的标题:)
-
我是否需要在代码中添加一些内容以反映控制面板中的更改。在 cmd 提示符下执行时,command 工作正常。
标签: java swing process controlpanel