'Getting the list of softwares installed using Java on a computer
How can one get a list of installed software and its version in Java?
Solution 1:[1]
There's another question on StackOverflow that checks for the existence of a particular software.
You can make a list of all filepaths that have
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
in the beginning, then take whatever is at the end of this filepath to be the name of the software.
Solution 2:[2]
I think following code might help you. I am new to java so pls edit my code if any changes.
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class getInstalledAppList {
private static final String REGQUERY_UTIL = "reg query ";
private static final String REGSTR_TOKEN = "REG_SZ";
static String s = REGQUERY_UTIL + "HKEY_LOCAL_MACHINE\\Software"
+ "\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
public static String getCurrentUserPersonalFolderPath() {
try {
Process process = Runtime.getRuntime().exec(s);
StreamReader reader = new StreamReader(process.getInputStream());
reader.start();
process.waitFor();
reader.join();
String result = reader.getResult();
int p = result.indexOf(REGSTR_TOKEN);
if (p == -1)
return null;
return result.substring(p + REGSTR_TOKEN.length()).trim();
}
catch (IOException | InterruptedException e) {
return null;
}
}
static class StreamReader extends Thread {
private final InputStream is;
private final StringWriter sw;
StreamReader(InputStream is) {
this.is = is;
sw = new StringWriter();
}
@Override
public void run() {
try {
int c;
while ((c = is.read()) != -1)
sw.write(c);
}
catch (IOException e) { e.printStackTrace(); }
}
String getResult() {
return sw.toString();
}
}
public static void main(String s[]) {
getDisplayNameDword( getCurrentUserPersonalFolderPath() );
}
private static void getDisplayNameDword(String str){
Set<String> set = new HashSet<>();
String [] array = new String[500];
array = str.split("\n");
for(String i : array){
set.add( getName(i.trim()) );
}
Iterator i = set.iterator();
while(i.hasNext()){
System.out.println( i.next() );
}
}
private static String getName(String s){
Process process = null;
try {
// Run reg query, then read output with StreamReader (internal class)
process = Runtime.getRuntime().exec("reg query " +
'"'+ s + "\" /v " + "DisplayName");
StreamReader reader = new StreamReader(process.getInputStream());
reader.start();
process.waitFor();
reader.join();
// Parse out the value
String[] parsed = reader.getResult().split(REGSTR_TOKEN);
if (parsed.length > 1) {
return (parsed[parsed.length-1]).trim();
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
return null;
}
}
or use psinfo.exe to get installed app list in windows.
Solution 3:[3]
I wrote a little library (JavaListApps) that does this based on ListPrograms which is in turn based on a VB Script linked from a StackOverflow Post
My need is a little limited, so there are unimplemented parts compared to the C++ version.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Community |
Solution 2 | Kushal |
Solution 3 | drone.ah |