Solved

IF not working

Posted on 2014-10-13
6
74 Views
Last Modified: 2014-10-17
I've got a simple script which is comparing a system variable with a string:-

IF NOT "%MASTER_VERSION%" =="W7x64.ent.mui.2014.a.06" goto wrongVersion
got correctVersion

:wrongVersion
echo ---------------------------------------------------------
echo This is the incorrect script, please run correct.
echo ---------------------------------------------------------
pause
goto gotoEnd

:correctVersion
pause

Open in new window


If I echo out %master_version% I get the correct value:-
echo %MASTER_VERSION%
W7x64.ent.mui.2014.a.06

Open in new window


So all looks right, but cant get it to fail as wrong version, does anyone know what Im doing wrong?

Thank you
0
Comment
Question by:tonelm54
  • 3
  • 2
6 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40376808
On  mobile at the moment but looks like just remove the space before equals you have dot instead of goto
0
 

Author Comment

by:tonelm54
ID: 40376842
Took the space out, but still doesnt work. Got no .
0
 

Author Comment

by:tonelm54
ID: 40376853
So what I have soo far is:-
echo off
cls

IF NOT "%MASTER_VERSION%"=="W7x64.ent.mui.2014.a.06" goto wrongVersion

:wrongVersion
echo "%MASTER_VERSION%"
echo "W7x64.ent.mui.2014.a.06"

echo ---------------------------------------------------------
echo This is the incorrect script, please run correct.
echo ---------------------------------------------------------
pause
goto gotoEnd

:correctVersion
echo Ok

:gotoEnd
pause

Open in new window


Which outputs:-

"W7x64.ent.mui.2014.a.06"
"W7x64.ent.mui.2014.a.06"
---------------------------------------------------------
This is the incorrect script, please run correct.
---------------------------------------------------------
Press any key to continue . . .

So as you can see both variables are the same, so it should say "Ok", not run wrongVersion
0
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.

 

Author Comment

by:tonelm54
ID: 40376858
Ok, figured it out, it looks like issue was becuase no (), this works:-
echo off
cls

IF NOT "%MASTER_VERSION%"=="W7x64.ent.mui.2014.a.06" (GOTO :wrongVersion) ELSE (GOTO :correctVersion)

:wrongVersion
echo "%MASTER_VERSION%"
echo "W7x64.ent.mui.2014.a.06"

echo ---------------------------------------------------------
echo This is the incorrect script, please run correct.
echo ---------------------------------------------------------
pause
goto gotoEnd

:correctVersion
echo Ok

:gotoEnd
pause

Open in new window

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40376974
Sorry autocorrect 'helping ' on mobile there. Your original had GOT not GOTO so always fell through. Will look at script properly when on PC in bit if wanted.

Steve
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 40379594
You had a couple of typos in your first post, I think this would correct those:
IF NOT "%MASTER_VERSION%" == "W7x64.ent.mui.2014.a.06" goto wrongVersion
goto correctVersion

:wrongVersion
echo ---------------------------------------------------------
echo This is the incorrect script, please run correct.
echo ---------------------------------------------------------
pause
goto :EOF

:correctVersion
pause

Open in new window

However, I would suggest a slight rewrite to look like this.  It avoids the goto's which is typically a little easier to follow and maintain.
IF "%MASTER_VERSION%" == "W7x64.ent.mui.2014.a.06" (
  echo ---------------------------------------------------------
  echo This is the incorrect script, please run correct.
  echo ---------------------------------------------------------
  pause
  goto :EOF
)

pause

Open in new window

~bp
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

706 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

20 Experts available now in Live!

Get 1:1 Help Now