VBA Hide Execution of Command Prompt

aje35

New Member
Joined
Jun 22, 2010
Messages
47
I have a command prompt utility called Net-SNMP that allows me to communicate with devices via SNMP.

Since there are quite a few devices I've tried to streamline the process by running the command prompt command from VBA.

The following function is something I pieced together.
Code:
    Function GetSNMP(IP As String, OID As String, Optional Community As String)    
         If Community = Empty Then
             Community = "public"
         End If
    
         Set S = CreateObject("wscript.shell")
         ComString = "snmpget -v 2c -c " & Community & " " & IP & " " & OID
         Set S = S.Exec(ComString)
         GetSNMP = S.StdOut.ReadAll
    End Function

The main problem I am having is that each execution of this function opens up a command prompt window. A secondary problem I'm having is when a SNMP connection can't be made the command prompt command waits about 10 seconds before it times-out. I want to be able for this function to run without any window popping up and also if there is no response from the command prompt for 1-2 seconds I want it to give up.

I did look in to the .run method to execute commands but I wasn't sure how to pass the return back in to VBA using this.

Looking for any solutions to get the job done.

Cheers!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,216,082
Messages
6,128,713
Members
449,464
Latest member
againofsoul

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top