Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-03-18
3
Medium Priority
?
547 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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…
Suggested Courses

824 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