use of com.sun.jna.platform.win32.COM.COMUtils.COMInfo in project jna by java-native-access.
the class COMInfoUtil method main.
public static void main(String[] args) {
FileWriter writer = null;
try {
String filename = new File(Helper.tempDir, "CLSIDs.txt").getAbsolutePath();
ArrayList<COMInfo> comInfos = COMUtils.getAllCOMInfoOnSystem();
writer = new FileWriter(filename);
for (COMInfo comInfo : comInfos) {
String result = "CLSID: " + comInfo.clsid + "\n";
result += "InprocHandler32: " + comInfo.inprocHandler32 + "\n";
result += "InprocServer32: " + comInfo.inprocServer32 + "\n";
result += "LocalServer32: " + comInfo.localServer32 + "\n";
result += "ProgID: " + comInfo.progID + "\n";
result += "ProgTypeLibID: " + comInfo.typeLib + "\n";
writer.write(result + "\n");
}
System.out.println("file written to: " + filename);
System.out.println("Found CLSID`s on the system: " + comInfos.size());
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of com.sun.jna.platform.win32.COM.COMUtils.COMInfo 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;
}
Aggregations