Click here to Skip to main content
Click here to Skip to main content

Tagged as

VBScript to check - Am I connected to VPN?

, 9 May 2013
Rate this:
Please Sign up or sign in to vote.
VBScript to check - Am I connected to VPN?

Introduction

Recently while developing automation utility using VBScript, I had to check if my machine is connected to VPN. I gone through many links on Google to find exact code of my requirement and get my automation done. But couldn't found the exact code which checks, if machine is connected to VPN. Sharing VBScript code here which tells you if your machine is connected to VPN.

Using the code

We are going to create below two files to test this code.

  1. testScript.vbs (VBScript file)
  2. testBatch.bat (batch file to call the above VBScript file)

Create testScript.vbs (VBScript file) and add below code in it.

Wscript.Echo IsVPNConnected()

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(LCase(objItem.Description),"vpn")) Then
     IsVPNConnected = objItem.IPEnabled     
    End If

   Next
   

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

End Function

Create testBatch.bat file using Notepad and add below lines to it.

cscript /nologo testScript.vbs

pause

Run testBatch.bat file to see if you are connected to VPN.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

RaisKazi
Technical Lead
United States United States
No Biography provided

Comments and Discussions

 
QuestionThank you. Pinmemberryad ramoul31-Oct-13 3:48 
AnswerRe: Thank you. PinmemberRaisKazi31-Oct-13 3:51 
GeneralRe: Thank you. Pinmemberryad ramoul31-Oct-13 4:09 
GeneralRe: Thank you. PinmemberRaisKazi31-Oct-13 5:59 
GeneralRe: Thank you. PinmemberTuân Hồ15-Jul-14 6:53 
GeneralRe: Thank you. PinmemberRaisKazi15-Jul-14 8:20 
GeneralRe: Thank you. PinmemberTuân Hồ16-Jul-14 8:39 
GeneralMy vote of 3 Pinmemberemartinho9-May-13 6:09 
GeneralRe: My vote of 3 PinmemberRaisKazi9-May-13 8:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140826.1 | Last Updated 9 May 2013
Article Copyright 2013 by RaisKazi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid