SNMP GEt using WMI

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone have any samples or references to get me started with WMI for collecting SNMP information? Any help is appreciated.

Thanks,
Dan
 
I found the following example for use with windows scripting. I made some minor tweeks to get it to compile in vb.net. Question; is it considered bad form to be using 'CreateObject' in .net? Is there a more .net recommended way of doing the same thing?

Thanks,
Dan


Dim strTargetSnmpDevice As String = "127.0.0.1"
Dim strTargetSnmpCommunity As String = "public"

Dim objWmiLocator As Object = CreateObject("WbemScripting.SWbemLocator")
Dim objWmiServices As Object = objWmiLocator.ConnectServer("", "root\snmp\localhost")

Dim objWmiNamedValueSet As Object = CreateObject("WbemScripting.SWbemNamedValueSet")
objWmiNamedValueSet.Add("AgentAddress", strTargetSnmpDevice)
objWmiNamedValueSet.Add("AgentReadCommunityName", strTargetSnmpCommunity)

Dim colSystem = objWmiServices.InstancesOf("SNMP_RFC1213_MIB_system", , objWmiNamedValueSet)

For Each objSystem As Object In colSystem
Console.WriteLine("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

Console.Read()
 
Dan this is only to prevent that everone opens again and again your double
message.
I have no answer on this one, however you have posted it twice.
 
Have a look at the System.Management namespace.
______________________________________
The Grim Reaper

Dan said:
I found the following example for use with windows scripting. I made some
minor tweeks to get it to compile in vb.net. Question; is it considered bad
form to be using 'CreateObject' in .net? Is there a more .net recommended
way of doing the same thing?
Thanks,
Dan


Dim strTargetSnmpDevice As String = "127.0.0.1"
Dim strTargetSnmpCommunity As String = "public"

Dim objWmiLocator As Object = CreateObject("WbemScripting.SWbemLocator")
Dim objWmiServices As Object = objWmiLocator.ConnectServer("", "root\snmp\localhost")

Dim objWmiNamedValueSet As Object = CreateObject("WbemScripting.SWbemNamedValueSet")
objWmiNamedValueSet.Add("AgentAddress", strTargetSnmpDevice)
objWmiNamedValueSet.Add("AgentReadCommunityName", strTargetSnmpCommunity)

Dim colSystem =
objWmiServices.InstancesOf("SNMP_RFC1213_MIB_system", , objWmiNamedValueSet)
For Each objSystem As Object In colSystem
Console.WriteLine("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)
 
Back
Top