If (not) String1==String2 goto :END

Posted on 2006-05-25
Last Modified: 2012-06-21
Hi there,

I have a batch file I want to run and I want it to be dependent on %ComputerName%

So if I use the IF command in DOS I'd like it to match the computername to those listed in a text file.

Any help would be great,


Question by:qvhit
    LVL 14

    Accepted Solution

    take a look at this:

    @echo off
    set found=0
    for /f %%a in (computername.txt) do if {%COMPUTERNAME%)=={%%a} set found=1

    if %found%==1 echo found
    if %found%==0 echo not found
    LVL 10

    Expert Comment

    The closest thing I can come up with to match your subject would be:

    find /I "%computername%" computernames.txt >NUL&if errorlevel 1 goto :EOF

    So something like:
    @echo off
    find /I "%computername%" computernames.txt >NUL&if errorlevel 1 goto :EOF
    echo Prossing.

    Author Comment

    Cheers cwwkie your answer seemed to work fine (just had to tweak the brackets) so I shall be giving you the points

    GuruGary - thanks for responding I was going to split the points if I found that your answer worked but unfortunately I don't have time to check it.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
    Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    730 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

    17 Experts available now in Live!

    Get 1:1 Help Now