Accessing MIBs programatically using WMI

Posted on 2004-09-24
Last Modified: 2012-06-21
I found this example on technet and it works great.  If i open up the RFC1213 MIB and look around I can change the code to access different OIDs.  The question I have is how does one know what to put in script to access another MIB?  They use the string "SNMP_RFC1213_MIB_ifTable".  What if I want to use a different MIB?

strTargetSnmpDevice = ""
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 colIfTable = objWmiServices.InstancesOf("SNMP_RFC1213_MIB_ifTable", , _
For Each objInterface In colIfTable
    WScript.Echo "ifIndex [Key]:        " & objInterface.ifIndex  & vbCrLf & _
        "   ifAdminStatus:     " & objInterface.ifAdminStatus     & vbCrLf & _
        "   ifDescr:           " & objInterface.ifDescr           & vbCrLf & _
        "   ifInDiscards:      " & objInterface.ifInDiscards      & vbCrLf & _
        "   ifInErrors:        " & objInterface.ifInErrors        & vbCrLf & _
        "   ifInNUcastPkts:    " & objInterface.ifInNUcastPkts    & vbCrLf & _
        "   ifInOctets:        " & objInterface.ifInOctets        & vbCrLf & _
        "   ifInUcastPkts:     " & objInterface.ifInUcastPkts     & vbCrLf & _
        "   ifInUnknownProtos: " & objInterface.ifInUnknownProtos & vbCrLf & _
        "   ifLastChange:      " & objInterface.ifLastChange      & vbCrLf & _
        "   ifMtu:             " & objInterface.ifMtu             & vbCrLf & _
        "   ifOperStatus:      " & objInterface.ifOperStatus      & vbCrLf & _
        "   ifOutDiscards:     " & objInterface.ifOutDiscards     & vbCrLf & _
        "   ifOutErrors:       " & objInterface.ifOutErrors       & vbCrLf & _
        "   ifOutNUcastPkts:   " & objInterface.ifOutNUcastPkts   & vbCrLf & _
        "   ifOutOctets:       " & objInterface.ifOutOctets       & vbCrLf & _
        "   ifOutQLen:         " & objInterface.ifOutQLen         & vbCrLf & _
        "   ifOutUcastPkts:    " & objInterface.ifOutUcastPkts    & vbCrLf & _
        "   ifPhysAddress:     " & objInterface.ifPhysAddress     & vbCrLf & _
        "   ifSpecific:        " & objInterface.ifSpecific        & vbCrLf & _
        "   ifSpeed:           " & objInterface.ifSpeed           & vbCrLf & _
        "   ifType:            " & objInterface.ifType            & vbCrLf
Question by:stealth188
  • 4
  • 4
LVL 41

Expert Comment

ID: 12150589
I'd suggest that you use the WMI tools from microsoft to browse the SNMP namespaces
LVL 96

Expert Comment

by:Bob Learned
ID: 12157069
What is your requirement that makes you ask this question?  What information are you needing to access with WMI?


Author Comment

ID: 12157533
I am trying to access the following OID.  A gentleman was kind enough to tell me where to find the data but now that I am trying to implement it i'm consfused about how to tell WMI what MIB to look at.
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.


Author Comment

ID: 12157721
I can't see where I can pass a community string when I am trying to connect to "root\snmp\localhost".  It just gives me an error saying that WMI is unavailable on that host.  Makes sense because it isn't a Windows device.  I'm sure i'm being dense but can you give me a hint as to how I can connect using the tools?
LVL 96

Expert Comment

by:Bob Learned
ID: 12159333
Here is the .NET way:

   Public Function SystemDriverList() As ArrayList

      Dim arrayDrivers As ArrayList = New ArrayList


         Dim searchDrivers As System.Management.ManagementObjectSearcher = _
            New System.Management.ManagementObjectSearcher( _
            "Select * FROM Win32_SystemDriver")

         Dim objectDriver As System.Management.ManagementObject

         For Each objectDriver In searchDrivers.Get()



      Catch ex As Exception


      End Try

      Return arrayDrivers

   End Function

We would just need to find the Win32 WMI class that provides you the information that you need.


Author Comment

ID: 12160866
.Net says that is not a valid namespace.  Do I need to install something in order to access the namespace?
LVL 96

Expert Comment

by:Bob Learned
ID: 12160901
Yes, you need to add a reference to the System.Management.dll.


Author Comment

ID: 12163697
That seems to return a list of services on my local PC.  How can I convince it to interrogate the router?

LVL 96

Accepted Solution

Bob Learned earned 500 total points
ID: 12163732
I am sorry for the confusion.  I was trying to say that this is only a starting example.  We need to find the right Win32 class and the properties for the device you are querying.  Here is a list of the Win32 classes:


Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tracing a live website down to the files which support it 2 30
IDE for Python 5 62
WPF user control poped up from a window 1 35 Excel Add-in 2 14
IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question