Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Lagittaja/14e464a8d1bb9335f7714e0380c0554d to your computer and use it in GitHub Desktop.
Save Lagittaja/14e464a8d1bb9335f7714e0380c0554d to your computer and use it in GitHub Desktop.
Windows 10 - Delay Mapping Network Drives Until Interface is Up
@echo off
set "Server=192.168.50.125"
set "RetryCount=0"
:CheckServer
rem Ping server only once with a time limit of 1000 ms.
%SystemRoot%\System32\ping.exe -n 1 -w 1000 %Server% >nul
if not errorlevel 1 goto MapDrive
rem Connection to server is not yet established. Give up after 30 seconds
rem in case of not being in right LAN or no network connection at all or
rem this server is currently not running.
set /A RetryCount+=1
if not %RetryCount%==30 goto CheckServer
echo There is no connection to server %Server%.
echo The network drive P: is not available.
echo The network drive W: is not available.
goto :EOF
:MapDrive
echo Removing existing P: drive if it exists ...
%SystemRoot%\System32\net.exe P: /delete
echo Removing existing W: drive if it exists ...
%SystemRoot%\System32\net.exe W: /delete
echo Mapping network drive P: ...
%SystemRoot%\System32\net.exe use P: \\%Server%\public /persistent:no >nul
echo Mapping network drive W: ...
%SystemRoot%\System32\net.exe use W: \\%Server%\will /persistent:no >nul
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment