Get MS-Windows Installed Applications from Java

后端 未结 3 1297
孤城傲影
孤城傲影 2021-01-20 06:33

Is it possible to get a list of installed applications (like the list from the un-install programs) from a windows vista computer with java?

相关标签:
3条回答
  • 2021-01-20 06:40

    If you mean installed applications I don't think it's possible by directly using Java SDK (also because it's not a cross platform requirement).. what I think you can do is to use an external native API to interact with windows registry (like jRegistryKey) and retrieve the information you need..

    Instead if you want to get all the running applications from a Java program you could parse tasklist.exe output as explained here.

    0 讨论(0)
  • 2021-01-20 06:56

    Not a Solution but a workaround!!

    Getting windows native information using java SDK is not possible without support of external APIs. Instead of using external APIs (which is mostly LGPL licensed and not completely open), we can use the shell commands to get the same.

    For getting the installed softwares list, use ProcessBuilder or Runtime.exec to run one of the following PowerShell commands:

    1. Get-WmiObject -class Win32_Product | Select-Object -Property Name - This is bit slower! It uses Win32_Product class.
    2. Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate - This is faster and can give additional details. This uses PS registry provider.

    You can stream the output of these and process it.

    This is just a workaround and it is as per my analysis. As java is completely platform independent, fetching native information becomes difficult and the use of platform native tools (like command shell,, power shell etc.,) is a must.

    0 讨论(0)
  • 2021-01-20 07:04
    package Vishal;
    
    import com.sun.jna.platform.win32.Advapi32Util;
    import static com.sun.jna.platform.win32.WinReg.HKEY_LOCAL_MACHINE;
    import java.util.ArrayList;
    import java.util.TreeMap;
    
    public class GenerateInstalledApplicationList 
    {
        ArrayList<String> getlist()
        {
            ArrayList<String> arr = new ArrayList();
            String [] keys = Advapi32Util.registryGetKeys(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
        String temp;
        for (String key : keys) 
        {
            temp = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall" + "\\" +key;
            TreeMap<String, Object> tr = Advapi32Util.registryGetValues(HKEY_LOCAL_MACHINE,temp); 
            if(tr.isEmpty())
            {
                if(!key.contains("Update"))//all the instances of update are not actually installed applications
                {
                arr.add(key);
                }
            }
            else
            {
                if(tr.containsKey("DisplayName"))
                {
                    String str = (String) tr.get("DisplayName");
                    if(!str.contains("Update"))
                    {
                    arr.add(str);
                    }
                }
            }     
        }
        return arr;
       }}
    

    Just Copy and paste this code it will return all the installed applications only thing you will need is the jna api.

    0 讨论(0)
提交回复
热议问题