added
wmi crawler release
This commit is contained in:
parent
6d11a0a70c
commit
68a16c2c40
|
@ -32,15 +32,38 @@ public class WMICrawlerWindows extends WMICrawlerOS {
|
|||
ActiveXComponent wmi = null;
|
||||
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());
|
||||
|
||||
wmi.safeRelease();
|
||||
conRet.safeRelease();
|
||||
vCollection.safeRelease();
|
||||
|
||||
|
||||
Variant vItem = null;
|
||||
Dispatch item = null;
|
||||
|
||||
List<String> columns = null;
|
||||
|
@ -48,7 +71,8 @@ public class WMICrawlerWindows extends WMICrawlerOS {
|
|||
List<Map<String, String>> resultMapList = new ArrayList<Map<String, String>>();
|
||||
while (enumVariant.hasMoreElements()) {
|
||||
|
||||
item = enumVariant.nextElement().toDispatch();
|
||||
vItem = enumVariant.nextElement();
|
||||
item = vItem.toDispatch();
|
||||
|
||||
if (columns == null) {
|
||||
columns = getColumns(item);
|
||||
|
@ -57,14 +81,20 @@ public class WMICrawlerWindows extends WMICrawlerOS {
|
|||
resultMap = new HashMap<String, String>();
|
||||
String name = null;
|
||||
String value = null;
|
||||
Variant vValue = null;
|
||||
|
||||
for(int indexI = 0 ; indexI < columns.size(); ++indexI) {
|
||||
name = columns.get(indexI);
|
||||
value = Dispatch.call(item, name).toString();
|
||||
vValue = Dispatch.call(item, name);
|
||||
value = vValue.toString();
|
||||
resultMap.put(name, value);
|
||||
vValue.safeRelease();
|
||||
}
|
||||
|
||||
resultMapList.add(resultMap);
|
||||
|
||||
vItem.safeRelease();
|
||||
item.safeRelease();
|
||||
}
|
||||
return resultMapList;
|
||||
}
|
||||
|
@ -75,17 +105,37 @@ public class WMICrawlerWindows extends WMICrawlerOS {
|
|||
|
||||
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();
|
||||
|
||||
while (enumv.hasMoreElements()) {
|
||||
Dispatch vv = enumv.nextElement().toDispatch();
|
||||
newEnum.safeRelease();
|
||||
|
||||
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);
|
||||
|
||||
disElem.safeRelease();
|
||||
vElem.safeRelease();
|
||||
vName.safeRelease();
|
||||
}
|
||||
|
||||
enumv.safeRelease();
|
||||
return columns;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user