Jump to content
Sign in to follow this  
mfurman

Were i'm i going wrong with this script?

Recommended Posts

mfurman

I'm exploring and learning more of Autoit and i'm writing a script that will return the type of windows the customer has. The variable is being passed to the IF statement but it is crashing on comparison to the value in the variable

$os = @OSVersion

IF $os == WIN_XP Then
    MsgBox ( 1, "version of windows", "You have: Windows XP")
ElseIf $os == WIN_VISTA Then
    MsgBox ( 1, "version of windows", "You have: Windows Vista")
ElseIF $0s == WIN_7 Then
    MsgBox ( 1, "version of windows", "You have: Windows 7")
EndIf

Share this post


Link to post
Share on other sites
PsaltyDS

Put quotes around your literal strings:

IF $os == "WIN_XP" Then

:idea:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Tvern

And $0s should be $os (line 7)

Share this post


Link to post
Share on other sites
GEOSoft

Another method

$os = StringRegExpReplace(@OSVersion, "^.+_(.+)$", "$1")
MsgBox ( 1, "version of windows", "You have: Windows " & $os)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
mfurman

thank you everyone for your help

Share this post


Link to post
Share on other sites
mfurman

Geosoft, that looks pretty cool I just have no idea what that means yet i'm fairly new to programming and scripting in general

Share this post


Link to post
Share on other sites
GEOSoft

Geosoft, that looks pretty cool I just have no idea what that means yet i'm fairly new to programming and scripting in general

It takes @OSVersion apart as follows

^ = Start at the beginning of the string (not really required in this case)

.+_ = match but don't capture anything up to and including the underscore

(.+) = match and capture everything up to..

$ = the end of the string (again, this time it's not required but better to use it)

$1 = Replace the whole string with the captured group.

So in the case of Win_Vista, it won't bother capturing Win_ but it will capture Vista and then it replaces the whole string with Vista and that's what gets returned as $os.

RegEx and RegExReplace are powerfull (even if overused) tools and are ideal for this situation.

I could have done the same thing with

$os = StringMid(@OSVersion, StringInStr(@OSVersion, "_") +1)


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×