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

Posted on 2012-03-18
Last Modified: 2012-03-18

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
   THEN Issue Command
   ELSE Issue Another Command

Open in new window

What bat code would accomplish this?

Question by:SqueezeOJ
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 11

Accepted Solution

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


Author Closing Comment

ID: 37735255
Fast. Easy. Complete.
LVL 11

Expert Comment

ID: 37735501
Thank you !! :)

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

Suggested Solutions

Title # Comments Views Activity
Where can I find a virus scanner for XP SP2? 22 82
Need help Creating a Powershell script 8 56
cannot reinstall windows xp from cd on dell e520 cpu. 13 62
Powershell Split 18 29
Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

756 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