I'm trying to convert a MSDN routine from VBScript to JScript. I've
got everything but the last little bit. Of course like most things
without that last bit it is useless. The function gets SNMP data from
a remote device. I know that for the most part it is working (I
sniffed the network) but I haven't figured out the file translation to
get usable data.
The problem is the for loop. colSystem is an ActiveXObject and which
is apparently a container for another ActiveXObject. In VBScript the
For Each loop assigns each of the embedded objects to objSystem. My
trouble is that I have not been able to figure out the equivelent
functionality in JScript. Yes I did try "for in" but that did not
work.
The original routine in VBScript
(http://www.microsoft.com/technet/treeview/default.asp?url=/technet/ScriptCenter/network/scrnet07.asp):
********************
strTargetSnmpDevice = "192.168.0.1"
Set objWmiLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWmiServices = objWmiLocator.ConnectServer("",
"root\snmp\localhost")
Set objWmiNamedValueSet =
CreateObject("WbemScripting.SWbemNamedValueSet")
objWmiNamedValueSet.Add "AgentAddress", strTargetSnmpDevice
objWmiNamedValueSet.Add "AgentReadCommunityName", "public"
Set colSystem = objWmiServices.InstancesOf("SNMP_RFC1213_MIB_system",
, _
objWmiNamedValueSet)
For Each objSystem In colSystem
WScript.Echo "sysContact: " & objSystem.sysContact & vbCrLf & _
"sysDescr: " & objSystem.sysDescr & vbCrLf & _
"sysLocation: " & objSystem.sysLocation & vbCrLf & _
"sysName: " & objSystem.sysName & vbCrLf & _
"sysObjectID: " & objSystem.sysObjectID & vbCrLf & _
"sysServices: " & objSystem.sysServices & vbCrLf & _
"sysUpTime: " & objSystem.sysUpTime
Next
********************
My JScript version
var strTargetSnmpDevice = "192.168.0.1";
var connectServer = "winmgmts://./root/snmp/localhost";
var strQuery = "Select * from SNMP_RFC1213_MIB_system";
var wmiLocator = new ActiveXObject("WbemScripting.SWbemLocator");
var objWmiNamedValueSet =
ActiveXObject("WbemScripting.SWbemNamedValueSet");
var objWmiServices = wmiWmiLocator.ConnectServer("",
"root\snmp\localhost")
objWmiNamedValueSet.Add ("AgentAddress", strTargetSnmpDevice);
objWmiNamedValueSet.Add ("AgentReadCommunityName", "public");
var colSystem = new Enumerator
(ActiveXObject(connectServer).ExecQuery(strQuery,null,null,objWmiNamedValueSet));
// Problem Area
for (objSystem in colSystem)
{
WScript.Echo (" sysContact: " + objSystem.sysContact +
"\n sysDescr: " + objSystem.sysDescr +
"\n sysLocation: " + objSystem.sysLocation +
"\n sysName: " + objSystem.sysName +
"\n sysObjectID: " + objSystem.sysObjectID +
"\n sysServices: " + objSystem.sysServices +
"\n sysUpTime: " + objSystem.sysUpTime);
}
********************