Sign in to follow this  
Followers 0
rono1

IF ElseIF

9 posts in this topic

#1 ·  Posted (edited)

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



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

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

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

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

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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

Share this post


Link to post
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

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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

Share this post


Link to post
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

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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.

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  
Followers 0