• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 726
  • Last Modified:

check for cisco vpn connection...enabled or disabled

I have a CISCO Vpn anyconnect secure mobility client.
v 3.1.02040

Does any one know of a way in vba to check and see if a vpn connection is established or not ?

  • 3
1 Solution
You can ping far side of vpn connection. Details of WMI Win32_PingStatus you can find here:
Vba version:
Sub test()
If Ping("") Then
    MsgBox "Passed", vbOKOnly
    MsgBox "Failed", vbOKOnly
End If
End Sub
Public Function Ping(ByVal ComputerIP As String) As Boolean
    'You can use also name of computer
    ' Return TRUE, if pin was successful
   Dim oPingResult As Variant
    For Each oPingResult In GetObject("winmgmts://./root/cimv2").ExecQuery _
        ("SELECT * FROM Win32_PingStatus WHERE Address = '" & ComputerName & "'")
        If IsObject(oPingResult) Then
            If oPingResult.StatusCode = 0 Then
                Ping = True
                'Debug.Print "ResponseTime", oPingResult.ResponseTime 'You can also return ping time
               Exit Function
            End If
        End If
End Function

Open in new window

FordraidersAuthor Commented:
Thanks !
FordraidersAuthor Commented:
als315, This is passing any test i give it.  Off or on vpn ?
FordraidersAuthor Commented:
nm, this worked for now.
Function IsVPNConnected()
   IsVPNConnected = False
   sComputer = "."

   Set oWMIService = GetObject("winmgmts:\\" _
    & sComputer & "\root\CIMV2")

   Set colItems = oWMIService.ExecQuery( _
    "SELECT * FROM Win32_NetworkAdapterConfiguration", , 48)

   For Each objItem In colItems

'Please check description of your VPN Connection by running command "ipconfig /all" on command-line.

    If (InStr(objItem.Description, "AnyConnect")) Then
     IsVPNConnected = objItem.IPEnabled
    End If


   If (IsVPNConnected) Then
    IsVPNConnected = MsgBox("I am Connected to VPN.")
    IsVPNConnected = MsgBox("I am Not Connected to VPN.")
   End If

End Function
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now