?
Solved

If (not) String1==String2 goto :END

Posted on 2006-05-25
3
Medium Priority
?
935 Views
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,

Thanks,

Neil
0
Comment
Question by:qvhit
3 Comments
 
LVL 14

Accepted Solution

by:
cwwkie earned 150 total points
ID: 16761952
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
0
 
LVL 10

Expert Comment

by:GuruGary
ID: 16762387
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.
0
 

Author Comment

by:qvhit
ID: 16768452
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.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

749 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