Click here to Skip to main content
13,257,666 members (80,776 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 8 May 2013

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?


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


   If(IsVPNConnected) Then
    IsVPNConnected =  "I am Connected to VPN."
    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


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


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


About the Author

Technical Lead
United States United States
Full Stack Technology Professional

Hands-on experience with -
. Asp.Net, MVC, C#, Ajax
. JavaScript, Jquery, AngularJS
. Xamarin
. SharePoint
. VBScript

Tested flavors of -
. Java, Perl, Python, NodeJS, Android, IOS(little bit)

You may also be interested in...

Comments and Discussions

QuestionDidn't work for me Pin
twisterat574-Apr-17 5:31
membertwisterat574-Apr-17 5:31 
QuestionThank you. Pin
ryad ramoul31-Oct-13 4:48
memberryad ramoul31-Oct-13 4:48 
AnswerRe: Thank you. Pin
RaisKazi31-Oct-13 4:51
memberRaisKazi31-Oct-13 4:51 
GeneralRe: Thank you. Pin
ryad ramoul31-Oct-13 5:09
memberryad ramoul31-Oct-13 5:09 
GeneralRe: Thank you. Pin
RaisKazi31-Oct-13 6:59
memberRaisKazi31-Oct-13 6:59 
GeneralRe: Thank you. Pin
Tuân Hồ15-Jul-14 7:53
memberTuân Hồ15-Jul-14 7:53 
GeneralRe: Thank you. Pin
RaisKazi15-Jul-14 9:20
memberRaisKazi15-Jul-14 9:20 
GeneralRe: Thank you. Pin
Tuân Hồ16-Jul-14 9:39
memberTuân Hồ16-Jul-14 9:39 
GeneralMy vote of 3 Pin
emartinho9-May-13 7:09
memberemartinho9-May-13 7:09 
GeneralRe: My vote of 3 Pin
RaisKazi9-May-13 9:04
memberRaisKazi9-May-13 9:04 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 9 May 2013
Article Copyright 2013 by RaisKazi
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid