0

I need to get a full list of installed programs in Windows, through Java native code.

I've tried some suggestions and solutions others have pointed out, but I can't seem to get the whole list of programs.

The below code will successfully fetch most programs installed, but not all. I assume this has to do with not all programs having uninstallers, but I'm not sure at all.

try {
    Process pb = Runtime.getRuntime().exec(
                    "powershell.exe Get-ItemProperty HKLM:\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate");
    BufferedReader in = new BufferedReader(new InputStreamReader(pb.getInputStream()));
    String line;
    while ((line = in.readLine()) != null)
        System.out.println(line);
    } catch (IOException e) {
        e.printStackTrace();
    }
Vauxe
  • 53
  • 9
  • Possible duplicate of [Read/write to Windows registry using Java](https://stackoverflow.com/q/62289/5221149) – Andreas Sep 14 '19 at 20:38
  • 1
    *I can't seem to get the whole list of programs* - does it mean that you successfully called power shell, but the result does not contain some programs? In such case change the title, because the reason has nothing to do with Java. Registry does not necessarily contains all installed programs. The question should be *How can I find out all programs installed on Windows?* – mentallurg Sep 14 '19 at 21:28
  • @mentallurg Yes. I do successfully fetch **most** programs. I do miss a few, such as Dolby Audio, which I know does not have an "uninstaller". – Vauxe Sep 14 '19 at 21:41
  • 1
    See also [When Runtime.exec() won't](http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html) for many good tips on creating and handling a process correctly. Then ignore it refers to `exec` and use a `ProcessBuilder` to create the process. Also break a `String arg` into `String[] args` to account for things like paths containing space characters. – Andrew Thompson Sep 15 '19 at 00:37
  • This is just a piece of test code to make sure I get the proper list output. When I've got it, I use ProcessHandle instead of ProcessBuilder. – Vauxe Sep 15 '19 at 16:41

1 Answers1

0

There are different views on the meaning of installed. Some people consider as installed only the programs that have particular entries in the registry: entries about uninstaller, or entries about supported file types, or entries about COM/DCOM interfaces, etc. They don't consider so called portable programs as installed. The other consider as installed any program on the disk that is ready to be executed. This includes also portable programs.

You are considering as installed any programs on the disk.

In such cases there is no simple solution. To find all programs you should search through all directories on all your drives.

mentallurg
  • 4,967
  • 5
  • 28
  • 36
  • That makes sense. I was hoping not to have to iterate all paths looking for every .exe entry and the likes. I guess I was hoping Windows had some sort of automatic tracing of every runnable program, but that's a lot to ask isn't it. – Vauxe Sep 14 '19 at 22:08