wmi crawler   release
This commit is contained in:
snoop 2017-04-12 15:45:56 +09:00
parent 6d11a0a70c
commit 68a16c2c40

View File

@ -32,15 +32,38 @@ public class WMICrawlerWindows extends WMICrawlerOS {
ActiveXComponent wmi = null; ActiveXComponent wmi = null;
wmi = new ActiveXComponent("WbemScripting.SWbemLocator"); wmi = new ActiveXComponent("WbemScripting.SWbemLocator");
Variant conRet = wmi.invoke("ConnectServer", new Variant(ip), new Variant(nameSpace), new Variant(id), new Variant(pw)); Variant vIp = new Variant(ip);
Variant vNs = new Variant(nameSpace);
Variant vId = new Variant(id);
Variant vPw = new Variant(pw);
ActiveXComponent wmiconnect = new ActiveXComponent(conRet.toDispatch()); Variant conRet = wmi.invoke("ConnectServer", vIp, vNs, vId, vPw);
Variant vCollection = wmiconnect.invoke("ExecQuery", new Variant(query)); vIp.safeRelease();
vNs.safeRelease();
vId.safeRelease();
vPw.safeRelease();
Dispatch disConret = conRet.toDispatch();
ActiveXComponent wmiconnect = new ActiveXComponent(disConret);
disConret.safeRelease();
Variant vQuery = new Variant(query);
Variant vCollection = wmiconnect.invoke("ExecQuery", vQuery);
wmiconnect.safeRelease();
vQuery.safeRelease();
EnumVariant enumVariant = new EnumVariant(vCollection.toDispatch()); EnumVariant enumVariant = new EnumVariant(vCollection.toDispatch());
wmi.safeRelease();
conRet.safeRelease();
vCollection.safeRelease();
Variant vItem = null;
Dispatch item = null; Dispatch item = null;
List<String> columns = null; List<String> columns = null;
@ -48,7 +71,8 @@ public class WMICrawlerWindows extends WMICrawlerOS {
List<Map<String, String>> resultMapList = new ArrayList<Map<String, String>>(); List<Map<String, String>> resultMapList = new ArrayList<Map<String, String>>();
while (enumVariant.hasMoreElements()) { while (enumVariant.hasMoreElements()) {
item = enumVariant.nextElement().toDispatch(); vItem = enumVariant.nextElement();
item = vItem.toDispatch();
if (columns == null) { if (columns == null) {
columns = getColumns(item); columns = getColumns(item);
@ -57,14 +81,20 @@ public class WMICrawlerWindows extends WMICrawlerOS {
resultMap = new HashMap<String, String>(); resultMap = new HashMap<String, String>();
String name = null; String name = null;
String value = null; String value = null;
Variant vValue = null;
for(int indexI = 0 ; indexI < columns.size(); ++indexI) { for(int indexI = 0 ; indexI < columns.size(); ++indexI) {
name = columns.get(indexI); name = columns.get(indexI);
value = Dispatch.call(item, name).toString(); vValue = Dispatch.call(item, name);
value = vValue.toString();
resultMap.put(name, value); resultMap.put(name, value);
vValue.safeRelease();
} }
resultMapList.add(resultMap); resultMapList.add(resultMap);
vItem.safeRelease();
item.safeRelease();
} }
return resultMapList; return resultMapList;
} }
@ -75,17 +105,37 @@ public class WMICrawlerWindows extends WMICrawlerOS {
Variant propertyesa = Dispatch.call(item, "Properties_"); Variant propertyesa = Dispatch.call(item, "Properties_");
Variant newEnum = Dispatch.call(propertyesa.toDispatch(), "_NewEnum"); Dispatch disProperty = propertyesa.toDispatch();
Variant newEnum = Dispatch.call(disProperty, "_NewEnum");
propertyesa.safeRelease();
disProperty.safeRelease();
EnumVariant enumv = newEnum.toEnumVariant(); EnumVariant enumv = newEnum.toEnumVariant();
while (enumv.hasMoreElements()) { newEnum.safeRelease();
Dispatch vv = enumv.nextElement().toDispatch();
String vs = Dispatch.call(vv, "Name").toString(); Variant vElem = null;
Dispatch disElem = null;
Variant vName = null;
while (enumv.hasMoreElements()) {
vElem = enumv.nextElement();
disElem = vElem.toDispatch();
vName = Dispatch.call(disElem, "Name");
String vs = vName.toString();
columns.add(vs); columns.add(vs);
disElem.safeRelease();
vElem.safeRelease();
vName.safeRelease();
} }
enumv.safeRelease();
return columns; return columns;
} }