If (not) String1==String2 goto :END

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,


Who is Participating?
cwwkieConnect With a Mentor Commented:
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
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.
qvhitAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.