3Dmitchell Forum

Operating Systems => Windows => Topic started by: martinc on November 25, 2012, 12:23:50 PM



Title: VPN and Network Share batch file
Post by: martinc on November 25, 2012, 12:23:50 PM
Just a little batch file to
      1) Connect to a VPN
      2) Mount a network share
      3) Open folders of said network share
      4) Run a program
      5) Close said VPN and remove said network share

Code:
@echo off

ECHO.
ECHO   ####################################
ECHO  #                                    #
ECHO #  Connecting to VPN via batch script  #
ECHO  #                                    #
ECHO   ####################################
ECHO.

ECHO Wating to connect . . .
:: pinging nowhere and waiting in lieu of a sleep function
ping 1.1.1.1 -n 1 -w 1000 > nul
ECHO.

:: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
ECHO # Initiating VPN #
set connection_name=3Dmitch
set username=martinc
set password=pimpypassword

rasdial %connection_name% %username% %password%
ECHO.

:: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
ECHO # Mounting Shares #
set share_letter=D
set sharename="\\192.168.0.2\Data
set password=lamepassword
set username=mitch

net use %share_letter%: %sharename%" %password% /user:%username% /PERSISTENT:NO
ECHO.

:: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
ECHO # Opening Folders #
set sharename=\\192.168.0.2\Data
set folder1=%sharename%\dirA
set folder2=\dir2

"C:\Windows\explorer.exe" %folder1%
"C:\Windows\explorer.exe" %sharename%%folder2%
ECHO.

:: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
:: the script halts here until said program is closed
ECHO # Starting progams #
"C:\Program Files\whatever\you\want.exe"
ECHO.

:: the script continues after launching said program
::ECHO # Starting progams #
::"C:\Program Files\whatever\you\want.exe" &
::ECHO.

:: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
ECHO - - And now we undo everything - -
ping 1.1.1.1 -n 1 -w 1000 > nul

ECHO - - Disconnecting VPN - -
rasdial %connection_name% /disconnect
ECHO.

ECHO - - Removing shares - -
net use %share_letter% /delete /y
ECHO.

ECHO # - # - # - # - # - # - #
ECHO Thank You Come Again
ECHO - # - # - # - # - # - # -
ECHO.

:: to await input
:: PAUSE