Solved

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

Posted on 2012-03-18
3
496 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now