Solved

How to Check Net Use Find LPT2 in DOS Batch File (.bat)?

Posted on 2012-03-18
3
519 Views
Last Modified: 2012-03-18
Hello,

Writing short MS DOS batch (.bat) file for Windows XP and need to test result of NET USE.

Here's the pseudo-code of what I'd like to do...
NET USE | FIND "LPT2" --> Put Result Into LPT2-OK variable
IF LPT2-OK is TRUE
   THEN Issue Command
   ELSE Issue Another Command

Open in new window

What bat code would accomplish this?

Thanks,
Jason
0
Comment
Question by:SqueezeOJ
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
paultomasi earned 500 total points
ID: 37735001
How about something like this:
@echo off
net use | find "LPT2" >nul && "your-command-if-lpt2" || "your-command-if-not-lpt2"

Open in new window

To see this work, try the following:
@echo off
net use | find "LPT2" >nul && echo LPT2-OK || echo No LPT2

Open in new window

Or you could go for the traditional IF-statement like this:
@echo off
net use | find "LPT2" >nul
if %errorlevel% neq 1 (
    echo LPT2-OK
) else (
    echo No LPT2
)

Open in new window

0
 

Author Closing Comment

by:SqueezeOJ
ID: 37735255
Fast. Easy. Complete.
Thanks!
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 37735501
Thank you !! :)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
network copying issue 4 65
How can I modify this Excel worksheet with a script? 15 82
move command 5 56
Transfer configuration between Windows XP installations 4 56
If your system is showing symptoms of browser hijacks or 'google search redirects' check out my other article (http://rdsrc.us/u3GP7A) first and run the tool TDSSKiller (http://rdsrc.us/GDBBs4) to get rid of the infection. Once done, and if the …
We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

776 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