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" (http://www.abyssmedia.com/quickbfc/) and "Batch :::
::: File Compiler Pro" (http://www.bdargo.com/).  This method will  :::
::: at least remove your username and password from plain sight.    :::
:::                                                                 :::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::                             CREDITS                             :::
::: CREATED BY    : Jesse Bowes                                     :::
::: LAST MODIFIED : September 13, 2006                              :::
::: WEBSITE       : http://www.jessebowes.com                       :::
:::                                                                 :::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 
:************* 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  *************
 
@echo *** VPN CONNECTION UTILITY ***
 
@rasdial > c:\tempfile
@set /p STATUS= < c:\tempfile 
@del c:\tempfile
 
@IF "%status%" == "No connections"  GOTO MAKE
@GOTO CLOSE
 
:MAKE
@echo *** Establishing VPN connection ***
@rasdial %CONNNAME% %USERNAME% %PASS%
@echo *** Mapping Network drive ***
@PING 1.1.1.1 -n 1 -w 6000 >NUL
net use %DRIVE% %DRIVEMAP%
 
@GOTO END
 
:CLOSE
@echo *** Terminating VPN connection ***
@net use h: /delete
@rasdial %CONNNAME% /disconnect
@GOTO END
 
:END
@set STATUS=
@SET USERNAME=
@SET PASS=
@SET CONNNAME=
@SET DRIVE=
@SET DRIVEMAP=
pause
 

Comments:

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 vpnninja.com
Posted by dave on
so ! this means i have to change the user and pass and the domain to my actual info....cool
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.