Jump to content

IF ElseIF


rono1
 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...