Kevin Zhou
Kevin Zhou

Reputation: 1283

Command line string Variable comparison

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.

Upvotes: 9

Views: 18328

Answers (1)

dcp
dcp

Reputation: 55458

Try this:

if "%ComputerName%"=="A513242" (exit) else (echo "else taken")

Upvotes: 15

Related Questions