Skip to main content

How to Add a Network Printer in Batch Script

Provisioning new workstations or moving employees to different office floors requires a fast way to map printers. Manually going to "Add a Printer," scanning the network, and waiting for the driver wizard is a repetitive task that shouldn't be done by hand.

A Batch script can use the legacy but powerful PRINTUI command or a simple NET USE call (for older LPT mapping) to instantly connect a user to a shared printer on your server. This ensures that every employee has exactly the tools they need the moment they log in, without requiring a help-desk ticket.

This guide will explain how to automate network printer mapping.

Method 1: The Standard Connection (PRINTUI)

The printui.dll tool is the professional way to add a network printer. It handles the driver association and the connection in one step.

@echo off
set "PrinterPath=\\ServerName\PrinterShareName"

echo [ACTION] Connecting to network printer: %PrinterPath%...

:: Verify the print server is reachable before attempting connection
ping -n 1 -w 2000 ServerName >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Print server is not reachable: ServerName
echo Check the network connection and server name.
pause
exit /b 1
)

:: /in = Add a network printer connection
:: /n = Specify the network path
rundll32 printui.dll,PrintUIEntry /in /n "%PrinterPath%"

:: Verify the printer was added by checking if it appears in the list
timeout /t 3 >nul
wmic printer where "Name='%PrinterPath%'" get Name >nul 2>&1

if %errorlevel% equ 0 (
echo [SUCCESS] Printer added. It will now appear in your list.
) else (
echo [ERROR] Connection failed. Check the server path and permissions.
)

pause

Method 2: Adding and Setting as Default

Most users don't just want the printer added; they want it ready to use immediately without further clicks.

@echo off
set "Target=\\PrintServer-01\Floor2-Color"

echo [SETUP] Mapping and setting default printer...

:: Add the printer
rundll32 printui.dll,PrintUIEntry /in /n "%Target%"

:: Brief pause to allow the connection to register
timeout /t 3 >nul

:: Verify the printer was added before setting it as default
wmic printer where "Name='%Target%'" get Name >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Printer could not be added: %Target%
echo Cannot set as default. Check the path and permissions.
pause
exit /b 1
)

:: Set it as the default
rundll32 printui.dll,PrintUIEntry /y /n "%Target%"

echo [OK] %Target% is now your primary printer.
pause

Method 3: The "Silent Deployment" (No GUI)

Use the /q flag to suppress pop-up windows during login scripts or automated deployments.

@echo off
set "PrinterPath=\\SRV-PRNT\MFP-Main"

:: Check if the printer is already mapped to avoid duplicates
wmic printer where "Name='%PrinterPath%'" get Name >nul 2>&1
if %errorlevel% equ 0 (
echo [LOG] Printer already mapped: %PrinterPath%
exit /b 0
)

echo [LOG] Initializing office peripherals...

:: /q = Quiet mode (no GUI prompts)
rundll32 printui.dll,PrintUIEntry /in /n "%PrinterPath%" /q

echo [LOG] Peripheral mapping complete.

How to Avoid Common Errors

Wrong Way: Using "net use" for modern printers

The net use LPT1: \\server\printer command is for very old DOS-based software that needs to print to a physical parallel port. It does not install a modern printer in the Windows settings.

Correct Way: Use printui.dll (Method 1). This is the native Windows engine for managing printers and drivers in a modern graphical environment.

Problem: Driver Not Found

If the server doesn't have the "Point and Print" drivers for your specific version of Windows, the script will show a "Driver not found" error.

Solution: Ensure your print server has both x64 and x86 drivers uploaded, or use the /m flag in your script to point to a local driver INF file.

Best Practices and Rules

1. Unique Share Names

Ensure your printer shares on the server don't have spaces or complex characters. A simple name like \\Server\HR_Color is much easier to script than \\Server\Floor 2 HP Laser Jet (Copy 1).

2. Identify "Per-User" vs "Per-Machine"

By default, adding a network printer is a Per-User action. If User A logs in and runs the script, User B will not see the printer when they log in later. To add a printer for the entire computer (all users), use the /ga (Global Add) flag.

3. Verification

After the script runs, verify the printer is visible using a quick status check: wmic printer where "Name='\\\\ServerName\\PrinterShareName'" get Name

Conclusions

Adding network printers via Batch script is a fundamental building block of professional IT deployment.

By moving from manual wizard-based setup to automated command-line mapping, you eliminate human error and ensure a consistent printing experience across your entire organization.

This precision is essential for maintaining high productivity in offices, schools, and corporate environments where reliable document access is non-negotiable.