1
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 の自動更新を無効にするための私のコードです。実行すると、コンソールで「操作が正常に完了しました」という応答が返されますが、コントロール パネルに反映されない場合は、これに関して誰かが助けることができます。ありがとう

4

2 に答える 2