3

I'm using the WinRegistry class in my project and this is my code (Courtesy of Cravenica):

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);
    }
}

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"
for the key: "Adobe".
However, I'm getting this error:
"java.lang.IllegalArgumentException: The system can not find the specified path: 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies'".


I've also tried this:

List<String> ls = WinRegistry.subKeysForPath(
              WinRegistry.HKEY_LOCAL_MACHINE,
              "SOFTWARE\\Policies");
String adobeKey = ls.stream().filter(st -> st.matches("Adobe")).findAny().get();

But ls returns "null" with a NullPointerException, and I get the same error:
"java.lang.IllegalArgumentException: The system can not find the specified path: 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies'"


And I tried this (Courtesy of VGR):

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<String> keys = output.lines().filter(l -> !l.isEmpty());
        Stream<String> matches = keys.filter(l -> l.contains("\\Adobe"));
        Optional<String> key = matches.findFirst();
    }
    reg.waitFor();
}

But key returns "empty".

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??

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.

Display name
  • 95
  • 1
  • 2
  • 12
  • @HarryJohnston I checked and I'm running Java 64-bit on both systems and both systems are also 64-bit. – Display name Sep 29 '17 at 16:26
  • Process Monitor (available from the MS web site) might be a useful diagnostic tool. – Harry Johnston Sep 29 '17 at 23:13
  • Also, do you have the exact same version of Java on the machine that is working as on the one that doesn't? – Harry Johnston Sep 29 '17 at 23:17
  • @HarryJohnston The working computer is running 1.8.0_31 and the not-working computer is running 1.8.0_144. However, just today, the working version also stopped working. It's always the same error, saying it can't find system path HKLM\SOFTWARE\Policies. When I try to look for a HKCU path or any other registry path, it can't find any of them. – Display name Sep 30 '17 at 00:24
  • @HarryJohnston I have Process Monitor, but I don't know what I would be looking for. – Display name Sep 30 '17 at 00:25
  • You want to see whether the request is getting to the kernel or not, and if it is, what is looks like. For example, perhaps it is querying the current user's hive rather than the local machine hive. I'd start by searching for `Policies` because that part of the string is the least likely to have been mangled. – Harry Johnston Sep 30 '17 at 00:45

0 Answers0