Get MS-Windows Installed Applications from Java

后端 未结 3 1300
孤城傲影
孤城傲影 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 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 getlist()
        {
            ArrayList 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 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.

提交回复
热议问题