title: How to stop and start windows services in java on remote machine
body: <p>I have a java application that stops and starts windows services. I have a requirement that it should be able to do so on a <strong>remote machine</strong>. The current code I have for starting a Windows Service remotely looks as follows:</p>
  
  <pre><code>public void executeCommand() {
  
      String[] command = {"cmd.exe", "/c", "sc", "\\\\192.168.1.27", "start", "btwdins"};
      try {
          Process process = new ProcessBuilder(command).start();
          InputStream inputStream = process.getInputStream();
          InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
          BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
          String line;
          while ((line = bufferedReader.readLine()) != null) {
              System.out.println(line);
          }
      } catch (Exception ex) {
          System.out.println("Exception : " + ex);
      }
  }
  </code></pre>
  
  <p>However when running this I get the following error:</p>
  
  <pre><code>[SC] OpenSCManager FAILED 5:
  
  Access is denied.
  </code></pre>
  
  <p>Please note the following:</p>
  
  <ul>
  <li><p>Both local and remote machine are running on Windows 10</p></li>
  <li><p>The remote machine has it's firewall disabled</p></li>
  <li><p>RPC (Remote Procedure Call) is running on remote machine</p></li>
  <li><p>File and Printer sharing is turned on on remote machine</p></li>
  </ul>
  
  <p>What am I missing? Any help will be appreciated. </p>