Search in sources :

Example 1 with InfoKey

use of com.sun.jna.platform.win32.Advapi32Util.InfoKey in project jna by java-native-access.

the class COMUtils method getAllCOMInfoOnSystem.

/**
     * Gets the all com info on system.
     * 
     * @return the all com info on system
     */
public static ArrayList<COMInfo> getAllCOMInfoOnSystem() {
    HKEYByReference phkResult = new HKEYByReference();
    HKEYByReference phkResult2 = new HKEYByReference();
    String subKey;
    ArrayList<COMInfo> comInfos = new ArrayList<COMUtils.COMInfo>();
    try {
        // open root key
        phkResult = Advapi32Util.registryGetKey(WinReg.HKEY_CLASSES_ROOT, "CLSID", WinNT.KEY_READ);
        // open subkey
        InfoKey infoKey = Advapi32Util.registryQueryInfoKey(phkResult.getValue(), WinNT.KEY_READ);
        for (int i = 0; i < infoKey.lpcSubKeys.getValue(); i++) {
            EnumKey enumKey = Advapi32Util.registryRegEnumKey(phkResult.getValue(), i);
            subKey = Native.toString(enumKey.lpName);
            COMInfo comInfo = new COMInfo(subKey);
            phkResult2 = Advapi32Util.registryGetKey(phkResult.getValue(), subKey, WinNT.KEY_READ);
            InfoKey infoKey2 = Advapi32Util.registryQueryInfoKey(phkResult2.getValue(), WinNT.KEY_READ);
            for (int y = 0; y < infoKey2.lpcSubKeys.getValue(); y++) {
                EnumKey enumKey2 = Advapi32Util.registryRegEnumKey(phkResult2.getValue(), y);
                String subKey2 = Native.toString(enumKey2.lpName);
                if (subKey2.equals("InprocHandler32")) {
                    comInfo.inprocHandler32 = (String) Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, null);
                } else if (subKey2.equals("InprocServer32")) {
                    comInfo.inprocServer32 = (String) Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, null);
                } else if (subKey2.equals("LocalServer32")) {
                    comInfo.localServer32 = (String) Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, null);
                } else if (subKey2.equals("ProgID")) {
                    comInfo.progID = (String) Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, null);
                } else if (subKey2.equals("TypeLib")) {
                    comInfo.typeLib = (String) Advapi32Util.registryGetValue(phkResult2.getValue(), subKey2, null);
                }
            }
            Advapi32.INSTANCE.RegCloseKey(phkResult2.getValue());
            comInfos.add(comInfo);
        }
    } finally {
        Advapi32.INSTANCE.RegCloseKey(phkResult.getValue());
        Advapi32.INSTANCE.RegCloseKey(phkResult2.getValue());
    }
    return comInfos;
}
Also used : HKEYByReference(com.sun.jna.platform.win32.WinReg.HKEYByReference) ArrayList(java.util.ArrayList) EnumKey(com.sun.jna.platform.win32.Advapi32Util.EnumKey) InfoKey(com.sun.jna.platform.win32.Advapi32Util.InfoKey)

Aggregations

EnumKey (com.sun.jna.platform.win32.Advapi32Util.EnumKey)1 InfoKey (com.sun.jna.platform.win32.Advapi32Util.InfoKey)1 HKEYByReference (com.sun.jna.platform.win32.WinReg.HKEYByReference)1 ArrayList (java.util.ArrayList)1