Jump to content
Sign in to follow this  
rono1

IF ElseIF

Recommended Posts

rono1

Could anyone tell me why this script does not progress through the IF and ElseIF statments correctly based on @OSVersion? If I run it on WINNT it executes the install under Win2k and XP so it is not recognizing the OS or my scripting is incorrect.

Thanks...

IF FileExists(@ProgramFilesDir & "\Sophos\Sophos Anti-Virus\savmain.exe") Then

Exit

ElseIf @OSVersion = "WIN_XP" Or "WIN_2000" Then

RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)

WinKill("Uninstall", "")

RunWait("SoInstXP.exe")

Run("C:\sophostemp\xpmod.vbs")

RunWait('C:\sophostemp\setup.exe -ni')

WinKill("InstallShield Wizard", "")

ElseIF @OSVersion = "WIN_NT4" Then

RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)

WinKill("Uninstall", "")

RunWait("SoESNTv1.exe")

Run('C:\sophostemp\setup.exe -ni')

Else

Exit

EndIf

Exit

Edited by rono1

Share this post


Link to post
Share on other sites
seandisanti

Could anyone tell me why this script does not progress through the IF and ElseIF statments correctly based on @OSVersion? If I run it on WINNT it executes the install under Win2k and XP so it is not recognizing the OS or my scripting is incorrect.

Thanks...

IF FileExists(@ProgramFilesDir & "\Sophos\Sophos Anti-Virus\savmain.exe") Then

Exit

ElseIf @OSVersion = "WIN_XP" Or "WIN_2000" Then

RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)

WinKill("Uninstall", "")

RunWait("SoInstXP.exe")

Run("C:\sophostemp\xpmod.vbs")

RunWait('C:\sophostemp\setup.exe -ni')

WinKill("InstallShield Wizard", "")

ElseIF @OSVersion = "WIN_NT4" Then

RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)

WinKill("Uninstall", "")

RunWait("SoESNTv1.exe")

Run('C:\sophostemp\setup.exe -ni')

Else

Exit

EndIf

Exit

Maybe try using a Select-Case structure instead of the multiway if's

Share this post


Link to post
Share on other sites
rono1

Maybe try using a Select-Case structure instead of the multiway if's

I am not familiar with select-Case structure...

Share this post


Link to post
Share on other sites
seandisanti

I am not familiar with select-Case structure...

Select

Case <expression>

statement1

...

[Case

statement2

...][Case Else

statementN

...]

EndSelect

more details and example available in the help file

Share this post


Link to post
Share on other sites
rono1

Like this?

Select

case $var = FileExists(@ProgramFilesDir & "\Sophos\Sophos Anti-Virus\savmain.exe") Then

Exit

case $var2 = @OSVersion = "WIN_XP" Or "WIN_2000" Then

RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)

WinKill("Uninstall", "")

RunWait("SoInstXP.exe")

Run("C:\sophostemp\xpmod.vbs")

RunWait('C:\sophostemp\setup.exe -ni')

WinKill("InstallShield Wizard", "")

Case $var3 = @OSVersion = "WIN_NT4" Then

RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)

WinKill("Uninstall", "")

RunWait("SoESNTv1.exe")

Run('C:\sophostemp\setup.exe -ni')

EndSelect

Exit

Share this post


Link to post
Share on other sites
seandisanti

Like this?

Select

case $var = FileExists(@ProgramFilesDir & "\Sophos\Sophos Anti-Virus\savmain.exe") Then

Exit

case $var2 = @OSVersion = "WIN_XP" Or "WIN_2000" Then

RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)

WinKill("Uninstall", "")

RunWait("SoInstXP.exe")

Run("C:\sophostemp\xpmod.vbs")

RunWait('C:\sophostemp\setup.exe -ni')

WinKill("InstallShield Wizard", "")

Case $var3 = @OSVersion = "WIN_NT4" Then

RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)

WinKill("Uninstall", "")

RunWait("SoESNTv1.exe")

Run('C:\sophostemp\setup.exe -ni')

EndSelect

Exit

you don't need the "Then"'s

Share this post


Link to post
Share on other sites
rono1

I am receiving an error "WARNING: $var1: possibly used before declaration". What do you think is worng?

Select

Case $var1 = FileExists(@ProgramFilesDir & "\Sophos\Sophos Anti-Virus\savmain.exe")

Exit

Case $var2 = @OSVersion = "WIN_XP" Or "WIN_2000"

RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)

WinKill("Uninstall", "")

RunWait("SoInstXP.exe")

Run("C:\sophostemp\xpmod.vbs")

RunWait('C:\sophostemp\setup.exe -ni')

WinKill("InstallShield Wizard", "")

Case $var3 = @OSVersion = "WIN_NT4"

RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)

WinKill("Uninstall", "")

RunWait("SoESNTv1.exe")

Run('C:\sophostemp\setup.exe -ni')

EndSelect

Exit

Share this post


Link to post
Share on other sites
seandisanti

I am receiving an error "WARNING: $var1: possibly used before declaration". What do you think is worng?

Select

Case $var1 = FileExists(@ProgramFilesDir & "\Sophos\Sophos Anti-Virus\savmain.exe")

Exit

Case $var2 = @OSVersion = "WIN_XP" Or "WIN_2000"

RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)

WinKill("Uninstall", "")

RunWait("SoInstXP.exe")

Run("C:\sophostemp\xpmod.vbs")

RunWait('C:\sophostemp\setup.exe -ni')

WinKill("InstallShield Wizard", "")

Case $var3 = @OSVersion = "WIN_NT4"

RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)

WinKill("Uninstall", "")

RunWait("SoESNTv1.exe")

Run('C:\sophostemp\setup.exe -ni')

EndSelect

Exit

try this...

if FileExists(@ProgramFilesDir & "\Sophos\Sophos Anti-Virus\savmain.exe") Then Exit
$var2 = @OSVersion  
Select
Case $var2 = "WIN_XP" Or $var2 = "WIN_2000"
RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)
WinKill("Uninstall", "")
RunWait("SoInstXP.exe")
Run("C:\sophostemp\xpmod.vbs")
RunWait('C:\sophostemp\setup.exe -ni')
WinKill("InstallShield Wizard", "")
Case $var2  = "WIN_NT4"
RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)
WinKill("Uninstall", "")
RunWait("SoESNTv1.exe")
Run('C:\sophostemp\setup.exe -ni')
EndSelect
Exit

Share this post


Link to post
Share on other sites
rono1

try this...

if FileExists(@ProgramFilesDir & "\Sophos\Sophos Anti-Virus\savmain.exe") Then Exit
$var2 = @OSVersion  
Select
Case $var2 = "WIN_XP" Or $var2 = "WIN_2000"
RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)
WinKill("Uninstall", "")
RunWait("SoInstXP.exe")
Run("C:\sophostemp\xpmod.vbs")
RunWait('C:\sophostemp\setup.exe -ni')
WinKill("InstallShield Wizard", "")
Case $var2  = "WIN_NT4"
RunWait('msiexec.exe /X "{99747F0D-D4F8-4877-9CA0-4AE96D963633}" /q', @SystemDir)
WinKill("Uninstall", "")
RunWait("SoESNTv1.exe")
Run('C:\sophostemp\setup.exe -ni')
EndSelect
Exit

Thanks I think its working, now I will try executing it from a network share.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.