BlogVPN Batch Script

VPN Batch Script

Posted by Jesse on October 24, 2006

Here is a batch script I made to log me on/off of a vpn server and also mount/unmount a network drive.

I thought it would be useful to share

:::                        VPN.BAT OVERVIEW                         :::
::: This script automatically connects to a VPN Server and mounts   :::
::: a network drive for the connection.  If a connection is already :::
::: established, the script unmounts the drive and terminates the   :::
::: connection.                                                     :::
:::                                                                 :::
:::                           INSTRUCTIONS                          :::
::: To configure the script, edit your username, password, and the  :::
::: connection name below.  These are the criteria which let you    :::
::: log into your vpn server.   Next set the Drive you want to mount:::
::: as the DRIVE variable (eg. h:) and the location of the mount in :::
::: the DRIVEMAP Variable.  Run the script by double clicking.      :::
:::                                                                 :::
:::                            SECURITY                             :::
::: Due to the nature of batch files, anyone who has access to the  :::
::: file can also read the contents (most notably your username and :::
::: password).  I would recommend using a program to compile this   :::
::: batch into an EXE. I have tested this method using "Quick Batch :::
::: File Compiler" ( and "Batch :::
::: File Compiler Pro" (  This method will  :::
::: at least remove your username and password from plain sight.    :::
:::                                                                 :::
:::                             CREDITS                             :::
::: CREATED BY    : Jesse Bowes                                     :::
::: LAST MODIFIED : September 13, 2006                              :::
::: WEBSITE       :                       :::
:::                                                                 :::
:************* EDIT THESE *************
@SET USERNAME=username
@SET PASS=pass
@SET CONNNAME=as defined in 'Network Connections'
@SET DRIVE=h: (drive you want to mount)
@SET DRIVEMAP=\\server\username (location of mount)
:*************  END EDIT  *************
@rasdial > c:\tempfile
@set /p STATUS= < c:\tempfile 
@del c:\tempfile
@IF "%status%" == "No connections"  GOTO MAKE
@echo *** Establishing VPN connection ***
@echo *** Mapping Network drive ***
@PING -n 1 -w 6000 >NUL
net use %DRIVE% %DRIVEMAP%
@echo *** Terminating VPN connection ***
@net use h: /delete
@rasdial %CONNNAME% /disconnect
@set STATUS=


Posted by FRANCOKAREN23 on
If you are willing to buy a house, you would have to get the loan. Moreover, my mother commonly utilizes a commercial loan, which supposes to be the most firm.
Posted by Bjorn on
All is very easier when you're using Vpn Ninja, is the best in the world!!!!!I took it from
Posted by dave on
so ! this means i have to change the user and pass and the domain to my actual
can u gave me a free working vpn as an example. thanx alot
Posted by David on
Really nice example!
I save a LOT of time
thank you
Leave a Reply

(Your email will not be publicly displayed.)

Captcha Code

Click the image to see another captcha.