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 自动更新的代码。一旦我执行,我的控制台中就会收到“操作成功完成”的响应,但它没有反映在控制面板中,对此有什么帮助。谢谢