Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Reading an SNMP OID - Code Only Solution

Posted on 2001-06-27
Last Modified: 2012-08-13
I have to get the value of an SNMP OID in a code only solution. I've managed to open a session, but am struggling to send an OID and return valid data. If anyone can help complete the below function, or suggest a complete code replacement, the points are theirs.

I need a NON-3rd part control/dll/ocx solution. MGMTAPI.dll is allowed because its inherent to Windows NT.


Option Explicit
Private Declare Function SnmpMgrOpen Lib "MGMTAPI" (ByVal pszAgentAddress As Long, ByVal pszCommunityName As Long, ByVal nTimeout As Long, ByVal nRetries As Long) As Long
Private Declare Function SnmpMgrClose Lib "MGMTAPI" (ghMgmtSession As Long) As Long
Private Declare Function SnmpMgrRequest Lib "MGMTAPI" (ByVal ghMgmtSession As Long, ByVal requestType As Long, ByVal SnmpVarBindList As Long, ByVal nErrorStatus As Long, ByVal nErrorIndex As Long) As Long
Public Function GetSNMPData(ByVal strIPAddress As String, ByVal strCommunityString As String, ByVal strOID As String) As String
    Dim lngReturnCode As Long
    Dim lngSession As Long
    lngSession = SnmpMgrOpen(StrPtr(strIPAddress), StrPtr(strCommunityString), 1000, 3)
    If lngSession <> 0 Then

        ' lngReturnCode = SnmpMgrRequest(  << This is where I got stuck >>  )

        Call SnmpMgrClose(lngSession)
    End If
End Function
Sub Main()
    Debug.Print GetSNMPData("", "public", "")
End Sub
Question by:LadyVyxen
  • 5
  • 3
  • 3
  • +1

Expert Comment

ID: 6231216
I have a couple of suggestions;

First go to a site like
and get a trial of their software.  Even though you don't want to use it for
your final solution, it will help you to understand the construction and rules of SNMP messages.

Second, if you want an open-source example of an SNMP library you might start here;
you could also go to the Linux code storage website and get a Linux version, which
would also give you good examples.

I haven't used the MS SNMP functions, but there are some examples in the MSDN
library CD's.


Expert Comment

ID: 6231652
A further comment;
You said
I have to get the value of an SNMP OID in a code only solution.

If you only have to get one value from a fixed IP, then you could consider using
a "canned" message.  An SNMP message is such partly because it is sent
in UDP to a certain port.  You can hard code a message in the correct form
(including the BER conversion) and send it out, and if it's up the agent will

Expert Comment

ID: 6232465
For example, your debug request is for the "SystemId" which returns a string, ie.     HP ETHERNET MULTI-ENVIRONMENT,ROM A.05.03,JETDIRECT,JD24,EEPROM A.05.05

from a typical HP printer.

You might have to ask for depending on the type of request executed.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Comment

ID: 6234115
I've trolled through the Dart PowerTCP control, and its too high-level to be useful. I really need a function that does GetSNMPData(IP, Community, OID) that doesn't use 3'rd party. The reason for not using 3rd party is that our process for testing 3rd party products would take far longer than timescales set for this project, and I don't personally have time to dig in-depth into the protocol proper to be able to code at the winsock level.

Expert Comment

ID: 6234874
Then you're probably out of luck.  As far as I know I am the only person
using the E-E website who ever answers questions about SNMP, and I do
not know of a free SNMP library that is easy enough to use without some
understanding of SNMP.  And writing one would be considerably more than
however many points you have.

You may eventually get MGMTAPI to work, but I'm not sure it's happy under
NT (I used to have an NT machine, and thats when I decided to use dart.).
It is built into W2000 I think, but I don't know about WME.


Expert Comment

ID: 6253428
You are welcome to reject this, but even a "you can't do that" is an answer.

Author Comment

ID: 6254512
 For 300 points, "You can't do that" is not an acceptable answer when I've gotten about 80% of the code working already and just needed help with a single dll call (SnmpMgrRequest).
  It may be that noone on the list can help, which is fine, and is probably true as noone else has attempted an answer. But I *know* it *can* be done - Ive seen it done elsewhere, and I'm not after 3rd party OCXs, so this question has not been answered and is still an open query.
LVL 49

Expert Comment

ID: 7139866
Hi LadyVyxen,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Refund points and save as a 0-pt PAQ.

EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
DanRollins -- EE database cleanup volunteer

Author Comment

ID: 7140061
Actually, Im still waiting for an answer...!
LVL 49

Expert Comment

ID: 7140129
Hi LadyVyxen,
It's a sad fact, but if a question lies dormant for even one month, it will very seldom get an answer.  This question is OVER ONE YEAR OLD!  Time to swab the deck and blow the pipes.  Stick a fork in it Lady, this one is DONE :0)

Your best bet to get an answer is to post a new question and let this one close out (A Moderator will process the refund in seven days).  The Experts keep a hawkeye out for new 300- to 500-point questions, but they never bother to check these old ones.

-- Dan
LVL 49

Expert Comment

ID: 7140141
You might also consider thanking 3rsrichard for the help -- by accepting one of his comments as an answer -- even if it did not answer your question -- there was certainly some significant effort put in there.
-- Dan

Accepted Solution

Computer101 earned 0 total points
ID: 7178869
Placed in PAQ

E-E Moderator

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

856 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