Username Always stay logged in
Password:

 

Pages: [1]
  Print  
Author Topic: VPN and Network Share batch file  (Read 2760 times)
martinc
Global Moderator
Pro Designer
*****

Karma: +1/-0
Offline Offline

Posts: 148



View Profile
« on: November 25, 2012, 05:23:50 AM »

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

Logged

I have as much authority as the Pope, I just don't have as many people who believe it. --George Carlin
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
Greenday Theme Designed By [S.W.T]