Batch files are simple scripts used on Windows systems to automate routine tasks. Any file with the .bat extension contains a set of commands that Windows can execute line by line. These scripts are often used to:

  • Map shared network drives
  • Add shared printers
  • Update desktop shortcuts
  • Run recurring tasks whenever a user logs into Windows

With a little creativity, batch files can also be turned into interactive tools. For example, you can prompt users to select which shared drive they want to map, rather than forcing a predefined mapping.

Below is an introduction to the basic commands you will need, followed by a sample interactive script.


Batch File Basics

Here are some useful commands and how they work:

@echo

Outputs text to the screen.

@echo Hello World

Displays:

Hello World

Use @echo. (with a period) to print a blank line for readability.

@set

Creates or modifies a variable.

@set VARIABLE=

Sets a variable to an empty (null) value.

Reading user input

@set /P VARIABLE=Enter a number:

This displays text and waits for the user to type a value. Whatever they enter is stored in the variable.

Outputting a variable

@echo %VARIABLE%

Prints the value stored in that variable.

@pause

Pauses script execution and waits for the user to press a key.

@echo off

Stops Windows from displaying system commands while the script runs.
Use @echo on to turn that behavior back on.


Mapping Network Drives with Batch Files

To map a drive in Windows using a script, use:

net use {drive letter}: {path} /PERSISTENT:YES

For example:

net use F: \\192.168.1.4\movies /PERSISTENT:YES

The /PERSISTENT:YES option ensures the drive automatically reconnects at logon.


Sample Interactive Drive Mapping Script

Below is a cleaned up version of your example, formatted and corrected.
Save this in a text file with a .bat extension and double-click to run it.

@echo off
title DRIVE MAPPER v1.0

echo MAP YOUR DRIVE
echo.
echo --- SELECT A SHARE DRIVE ---
echo 1.) MOVIES FOLDER
echo 2.) PHOTOS FOLDER
echo 3.) MUSIC FOLDER
echo.

set /P DRIVE=Enter the number of the drive you want to map (1, 2, or 3): 
echo.

set /P DRIVELETTER=Enter the drive letter you want to use (for example, F): 
echo.

echo Your selected drive letter is: %DRIVELETTER%
pause

:: Map the correct folder based on selection
if "%DRIVE%"=="1" net use %DRIVELETTER%: \\192.168.1.4\movies /PERSISTENT:YES
if "%DRIVE%"=="2" net use %DRIVELETTER%: \\192.168.1.4\photos /PERSISTENT:YES
if "%DRIVE%"=="3" net use %DRIVELETTER%: \\192.168.1.4\music /PERSISTENT:YES

echo.
echo If you did not see any errors, your drive has been mapped successfully.
echo If you saw an error, the drive letter may already be in use or you entered an invalid option.
pause
@echo on

Final Thoughts

Interactive batch programs are a simple way to empower users and automate frequent tasks without installing additional software. Once you understand the basics of variables, input, and simple logic, you can build scripts that handle a wide range of processes.

If you want to expand this page, I can also create:

  • A more advanced version with error handling
  • A menu system using labels and GOTO
  • A PowerShell version suitable for modern Windows environments

Just let me know.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.