title: WinRegistry IllegalArgumentException error can't find path: 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies'
body: <p>I'm using the <a href="https://stackoverflow.com/questions/62289/read-write-to-windows-registry-using-java/6163701" title="WinRegistry">WinRegistry</a> class in my project and this is my code <em>(<a href="https://stackoverflow.com/a/39896368/7078496">Courtesy of Cravenica</a>)</em>:</p>
  
  <pre><code>public static void checkInstalled(){
      try {
          String regValue = null;
          regValue = WinRegistry.valueForKey(
              WinRegistry.HKEY_LOCAL_MACHINE, 
              "SOFTWARE\\Policies", 
              "Adobe");
          if(regValue == null) {
              System.out.println("Application not installed");
          } else {
              System.out.println("Application is installed");
          }
      } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException | IOException ex) {
          System.err.println(ex);
      }
  }
  </code></pre>
  
  <p>The code should be fairly straightforward. I'm trying to check if an Adobe application is installed on the user's machine by looking in the registry directory: "HKEY_LOCAL_MACHINE\SOFTWARE\Policies" <br/>for the key: "Adobe". 
  <br/>However, I'm getting this error: <br/><strong>"java.lang.IllegalArgumentException: The system can not find the specified path: 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies'"</strong>.<br/></p>
  
  <hr>
  
  <p>I've also tried this:</p>
  
  <pre><code>List&lt;String&gt; ls = WinRegistry.subKeysForPath(
                WinRegistry.HKEY_LOCAL_MACHINE,
                "SOFTWARE\\Policies");
  String adobeKey = ls.stream().filter(st -&gt; st.matches("Adobe")).findAny().get();
  </code></pre>
  
  <p>But <em>ls</em> returns "null" with a NullPointerException, and I get the same error:<br/>
  <strong>"java.lang.IllegalArgumentException: The system can not find the specified path: 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies'"</strong>
  <br/></p>
  
  <hr>
  
  <p>And I tried this <em>(<a href="https://stackoverflow.com/a/31236135/7078496">Courtesy of VGR</a>)</em>:</p>
  
  <pre><code>public static void checkInstalled() 
          throws IOException, InterruptedException{
      ProcessBuilder builder = new ProcessBuilder(
          "reg", "query", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies");
      Process reg = builder.start();
      try (BufferedReader output = new BufferedReader(
          new InputStreamReader(reg.getInputStream()))) {
          Stream&lt;String&gt; keys = output.lines().filter(l -&gt; !l.isEmpty());
          Stream&lt;String&gt; matches = keys.filter(l -&gt; l.contains("\\Adobe"));
          Optional&lt;String&gt; key = matches.findFirst();
      }
      reg.waitFor();
  }
  </code></pre>
  
  <p>But <em>key</em> returns "empty". <br/><br/>
  I know it's there. So what's going on?
  I have the registry open right now and I'm looking at the Adobe key right there in HKLM\SOFTWARE\Policies. Why does my program not see it??</p>
  
  <p>Update: I recreated the whole project on a different computer and I did not have the error. So, I went back and recreated the whole project on the original computer, and got the error again.</p>