Skip to content

Instantly share code, notes, and snippets.

@BattleNonSense
Last active June 7, 2023 20:56
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save BattleNonSense/6cb7cca393f44ba043705962949a179a to your computer and use it in GitHub Desktop.
Save BattleNonSense/6cb7cca393f44ba043705962949a179a to your computer and use it in GitHub Desktop.
Connect Network Drives in Windows
@echo off
echo CONNECT NETWORK DRIVES
echo //Created by Battle(non)sense - https://www.youtube.com/BattleNonSense
echo --------------------------------------------------------------------
echo This script waits for the network to be ready before connecting the network drives
echo --------------------------------------------------------------------
REM We need to wait for the network to get ready first
echo .
echo Waiting for Network
set LC=0
goto :waitfornet_
:waitfornet
timeout /t 1 /NOBREAK >nul
:waitfornet_
route print -4 | findstr /C:" 0.0.0.0 " >nul 2>nul
if not errorlevel 1 goto :ConnectNetDrives
set /A LC=%LC%+1
if %LC% LSS 30 goto :waitfornet
goto :eof
REM Once the network is ready we need to wait a bit before the next step or it might fail on some PC's
timeout /t 5 /nobreak >nul
:ConnectNetDrives
echo .
echo Network online, now connecting mapped network shares
REM Now we connect the network drives.
REM Template without login details: net use DRIVE: PATH /persistent:NO
REM net use O: \\server\footage /persistent:NO
REM Template with login details: net use DRIVE: PATH /user:NAME PASS /persistent:NO
REM net use O: \\server\footage /user:CHRIS MyStrongPazwrd /persistent:NO
net use
echo .
echo Done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment