Solved

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

Posted on 2008-10-03
3
249 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:Bonnie_K
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 22637394
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
 

Author Comment

by:Bonnie_K
ID: 22637553
Thanks!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 22637608
no prob
Steve
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question