Created
September 12, 2018 15:41
-
-
Save WillPresley/f50ed1085935f4a58f1af4d52a3e44d6 to your computer and use it in GitHub Desktop.
Windows 10 - Delay Mapping Network Drives Until Interface is Up
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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
Just what the doctor ordered. Thanks for sharing 👍