9

I've been trying to compare my computername to some pre-set string. From reading around on google, namely http://commandwindows.com/batchfiles-branching.htm, I've attempted the following and many variants of the same line with /I, "%ComputerName", A513242 etc

IF (%ComputerName% == "A513242") (
  EXIT) ELSE (
    ECHO "else taken")

where "A513242" is the result of calling ECHO %ComputerName% this seems to always take the "else taken" branch.

Any help as to why the (EXIT) case is not being taken/ what syntactical mistake I am making would be appreciated.

Albert Rothman
  • 998
  • 2
  • 9
  • 27
Kevin Zhou
  • 1,273
  • 4
  • 17
  • 25

1 Answers1

15

Try this:

if "%ComputerName%"=="A513242" (exit) else (echo "else taken")
dcp
  • 54,410
  • 22
  • 144
  • 164
  • Any explanation as to why OP's variant doesn't work? – klaus triendl Dec 17 '21 at 12:59
  • @klaus triendl - Refer to the accepted answer here: https://stackoverflow.com/questions/47035821/batch-if-else-condition-for-start-function-executes-regardless – dcp Dec 17 '21 at 16:04