Need to use batch file to check if lpt2 is already mapped

Hi,

I want to edit our login script to add a printer mapping for lpt2.

After it is done, I do not want it to remap every time the user logs in.

Is there a way to check if the port is mapped and skip the mapping?

THanks,
Bonnie
Bonnie_KAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Steve KnightConnect With a Mentor IT ConsultancyCommented:
You could use the fact that the command
net use lpt2: either returns an error if it isn;t connected or some text if it is:
It also set the error level so you could check with

@echo off
net use lpt2: >NUL 2>&1
if "%errorlevel%"=="0" ( echo LPT2: is already mapped ) ELSE (
net use lpt2: \\jamie\spool
echo Mapped the LPT2: for you now
)
0
 
Bonnie_KAuthor Commented:
Thanks!
0
 
Steve KnightIT ConsultancyCommented:
no prob
Steve
0
All Courses

From novice to tech pro — start learning today.