Map Local and Network Folders in Microsoft
In an enterprise environment, it is not uncommon for users to get their network folders disconnected on a regular basis. Problems can arise from VPN issues, power fluctuations, or other concerns. To help user’s get their connections back quickly you can make a batch script and save it on their desktop or in their startup folder. Rather than calling the service desk for help, user’s can just double click the file and restore their network folders.
Let’s create a script called ‘mapdrivces.bat’ using notepad. Add information to the headers. Anything with REM or :: will not be executed.
REM mapdrives.bat
REM Place a shortcut of this file in your startup folder or create
REM a task in task manager, to map drives whenever you login.
TITLE MAP NETWORK & LOCAL FOLDERS
Use ‘echo off’, at the top of the script. This tells the script to not display the commands or results to the screen, as they are executed. Use ‘echo.’ to print a blank line, and just plain echo to print any data to a screen.
@echo off
cls
echo ******************************************
date /t
echo.
echo Mapping folders . . .
echo.
Comment your code using descriptors and map the folder paths. The command to map network files is ‘net use’. Be sure to put quotes around the file path if there is a space somewhere in the path.
REM Map a Network Folder.
net use S: \\server_name\folder\folder
net use H: \\website.com\folder\folder
REM Map a local folder called scripts.
net use N: "\\localhost\c$\Users\<username>\Cool Stuff\scripts"
echo.
Finally, let’s create a short delay and exit the program. We can add the command ‘pause’ and it will hold the command prompt open until a key is struck or use ‘ping’ and it will wait three seconds and exit automatically.
echo All folders are mapped - End of Task
:: This will create a 3 sec delay before exiting.
:: ping 127.0.0.1 -n 3 -w 1000 > NUL
pause
echo.
exit
Now, open File Explorer and see your newly mapped folders.