how can use loop for and lists to define different versions of uninstalling a program?

Antworten
shirin
Beiträge: 7
Registriert: 20 Nov 2017, 12:16

how can use loop for and lists to define different versions of uninstalling a program?

Beitrag von shirin »

Hi,
I have a question: ''Ansys'' opsi package has 3 versions of 18.0 and 18.1 and 18.2 in my computer. Now I want to change the scripts , in which first uninstall the previos versions of 18.0 and 18.1 and also I should have uninstalling of v18.2 , and then installing v18.2.
I know that I should use
DefStringList $VersionList$
Set $VersionList$ = createStringList ('v180\', 'v181\', 'v182\')
...
for %s% in $list$ do...
but I donot know how exactly I can use these scripts , and also any other definitions?
had sombody the same problem and could help me?similar scripts?
These are my documents:
setup64.ins:


; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib
; and published under the Terms of the General Public License.
; credits: http://www.opsi.org/credits/

[Actions]
requiredWinstVersion >= "4.10.8.6"


DefVar $UninstallProgram$
DefVar $LogDir$
DefVar $ProductId$
DefVar $MinimumSpace$
DefVar $InstallDir$
DefVar $ExitCode$
DefVar $LicensePool$
DefStringList $VersionList$


Set $LogDir$ = "%SystemDrive%\tmp"

; ----------------------------------------------------------------
; - Please edit the following values -
; ----------------------------------------------------------------
;$ProductId$ should be the name of the product in opsi
; therefore please: only lower letters, no umlauts,
; no white space use '-' as a seperator
Set $ProductId$ = "ansys18"
Set $MinimumSpace$ = "27000 MB"
; the path were we find the product after the installation
Set $InstallDir$ = "%ProgramFiles64Dir%\ANSYS Inc\"
Set $VersionList$ = createStringList('v180\', 'v181\', 'v182\')

; ----------------------------------------------------------------

if not(HasMinimumSpace ("%SystemDrive%", $MinimumSpace$))
LogError "Not enough space on %SystemDrive%, " + $MinimumSpace$ + " on drive %SystemDrive% needed for " + $ProductId$
isFatalError
; Stop process and set installation status to failed
else
comment "Show product picture"
ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$

if FileExists("%ScriptPath%\delsub64.ins")
comment "Start uninstall sub section"
Sub "%ScriptPath%\delsub64.ins"
endif

Message "Installing " + $ProductId$ + " ..."

comment "Start setup program"
Winbatch_install
Sub_check_exitcode

endif

[Winbatch_install]
%ScriptPath%\setup\disk1\InstallPreReqs.exe -silent
%ScriptPath%\setup\disk1\setup.exe -silent -mechapdl -ansyscust -autodyn -lsdyna -cfdpost -cfx -turbogrid -fluent -polyflow -aqwa -icemcfd -forte -aim -acp -icepak -aviewer -rsm -ug -parasolid -solidedge -solidworks_reader -adinventor_reader -acad_reader -proe_reader -ug_reader -licserverinfo "2325:1055:ansys-lic.rrzn.uni-hannover.de" -install_dir "$InstallDir$" -disablerss -lang de -media_dir2 "%ScriptPath%\setup\disk2\"


[Sub_check_exitcode]
comment "Test for installation success via exit code"
set $ExitCode$ = getLastExitCode
; informations to exit codes see
; http://msdn.microsoft.com/en-us/library ... S.85).aspx
; http://msdn.microsoft.com/en-us/library/aa368542.aspx
if ($ExitCode$ = "0")
comment "Looks good: setup program gives exitcode zero"
else
comment "Setup program gives a exitcode unequal zero: " + $ExitCode$
if ($ExitCode$ = "1605")
comment "ERROR_UNKNOWN_PRODUCT 1605 This action is only valid for products that are currently installed."
comment "Uninstall of a not installed product failed - no problem"
else
if ($ExitCode$ = "1641")
comment "looks good: setup program gives exitcode 1641"
comment "ERROR_SUCCESS_REBOOT_INITIATED 1641 The installer has initiated a restart. This message is indicative of a success."
else
if ($ExitCode$ = "3010")
comment "looks good: setup program gives exitcode 3010"
comment "ERROR_SUCCESS_REBOOT_REQUIRED 3010 A restart is required to complete the install. This message is indicative of a success."
else
logError "Fatal: Setup program gives an unknown exitcode unequal zero: " + $ExitCode$
isFatalError
endif
endif
endif
endif

Uninstall64.ins:

; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib gmbh
; and published under the Terms of the General Public License.
; credits: http://www.opsi.org/credits/

[Actions]
requiredWinstVersion >= "4.10.8.6"

DefVar $UninstallProgram$
DefVar $LogDir$
DefVar $ExitCode$
DefVar $ProductId$
DefVar $InstallDir$
DefVar $UninstallProgram$
DefStringList $VersionList$


Set $LogDir$ = "%SystemDrive%\tmp"

; ----------------------------------------------------------------
; - Please edit the following values -
; ----------------------------------------------------------------
Set $ProductId$ = "ansys18"
Set $InstallDir$ = "%ProgramFiles64Dir%\ANSYS Inc\"
Set $VersionList$ = createStringList ('v180\', 'v181\', 'v182\')
; ----------------------------------------------------------------


comment "Show product picture"
ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$

Message "Uninstalling " + $ProductId$ + " ..."

if FileExists("%ScriptPath%\delsub64.ins")
comment "Start uninstall sub section"
Sub "%ScriptPath%\delsub64.ins"
endif

delsub64.ins

; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib gmbh
; and published under the Terms of the General Public License.
; credits: http://www.opsi.org/credits/

Set $UninstallProgram$ = $InstallDir$ + "\" + $VersionList$ + "\Uninstall.exe"
Message "Uninstalling " + $ProductId$ + " ..."
for %version% in $VersionList$ do Sub_uninstall


[Sub_uninstall]
if FileExists($UninstallProgram$)
comment "Uninstall program found, starting uninstall"
Winbatch_uninstall
sub_check_exitcode
endif

[Winbatch_uninstall]
$UninstallProgram$ -silent


[Sub_check_exitcode]
comment "Test for installation success via exit code"
set $ExitCode$ = getLastExitCode
; informations to exit codes see
; http://msdn.microsoft.com/en-us/library ... S.85).aspx
; http://msdn.microsoft.com/en-us/library/aa368542.aspx
if ($ExitCode$ = "0")
comment "Looks good: setup program gives exitcode zero"
else
comment "Setup program gives a exitcode unequal zero: " + $ExitCode$
if ($ExitCode$ = "1605")
comment "ERROR_UNKNOWN_PRODUCT 1605 This action is only valid for products that are currently installed."
comment "Uninstall of a not installed product failed - no problem"
else
if ($ExitCode$ = "1641")
comment "looks good: setup program gives exitcode 1641"
comment "ERROR_SUCCESS_REBOOT_INITIATED 1641 The installer has initiated a restart. This message is indicative of a success."
else
if ($ExitCode$ = "3010")
comment "looks good: setup program gives exitcode 3010"
comment "ERROR_SUCCESS_REBOOT_REQUIRED 3010 A restart is required to complete the install. This message is indicative of a success."
else
logError "Fatal: Setup program gives an unknown exitcode unequal zero: " + $ExitCode$
isFatalError
endif
endif
endif
endif

( but I think they have some errors.)

Thanks alot.
Benutzeravatar
n.wenselowski
Ex-uib-Team
Beiträge: 3194
Registriert: 04 Apr 2013, 12:15

Re: how can use loop for and lists to define different versions of uninstalling a program?

Beitrag von n.wenselowski »

Hi,

please use code blocks for further posts as they make reading easier. You can find it above the text input field.

I think your problem is here:

Code: Alles auswählen

Set $UninstallProgram$ = $InstallDir$ + "\" + $VersionList$ + "\Uninstall.exe"
Message "Uninstalling " + $ProductId$ + " ..."
for %version% in $VersionList$ do Sub_uninstall


[Sub_uninstall]
if FileExists($UninstallProgram$)
comment "Uninstall program found, starting uninstall"
Winbatch_uninstall
sub_check_exitcode
endif

[Winbatch_uninstall]
$UninstallProgram$ -silent
You need to set $UninstallProgram$ in your sub with the value from the for loop

Code: Alles auswählen

Message "Uninstalling " + $ProductId$ + " ..."
for %version% in $VersionList$ do Sub_uninstall

[Sub_uninstall]
Set $UninstallProgram$ = $InstallDir$ + "\" + %version% + "\Uninstall.exe"
if FileExists($UninstallProgram$)
    comment "Uninstall program found, starting uninstall"
    Winbatch_uninstall
    sub_check_exitcode
endif

[Winbatch_uninstall]
$UninstallProgram$ -silent

Kind regards

Niko

Code: Alles auswählen

import OPSI
shirin
Beiträge: 7
Registriert: 20 Nov 2017, 12:16

Re: how can use loop for and lists to define different versions of uninstalling a program?

Beitrag von shirin »

Thank you very much for your help Niko.
I changed my scripts and tried again, but still I have 2 errors:

Code: Alles auswählen

 [6] [Nov 20 19:04:09:028] [ansys18]     Set  $UninstallDir$ = $InstallDir$ + "\" + v180\ + "\Uninstall.exe"
(160)     [2] [Nov 20 19:04:09:028] [ansys18]     Syntax Error in Section: Sub_uninstall (Command in line 14 origin: p:\ansys18\uninstall64.ins line: 15): $UninstallDir$ = $InstallDir$ + "\" + v180\ + "\Uninstall.exe" -> v180\ + "\Uninstall.exe" illegal String Expressionstr
(161)     [6] [Nov 20 19:04:09:028] [ansys18]     
(162)     [6] [Nov 20 19:04:09:028] [ansys18]     ~~~~~~~ End Sub   ~~~~~~~  Sub_uninstall
(163)     [6] [Nov 20 19:04:09:028] [ansys18]     
(164)     [6] [Nov 20 19:04:09:028] [ansys18]     
(165)     [6] [Nov 20 19:04:09:028] [ansys18]     ~~~~~~~ Start Sub ~~~~~~~  Sub_uninstall
(166)     [6] [Nov 20 19:04:09:029] [ansys18]     
(167)     [6] [Nov 20 19:04:09:029] [ansys18]     ~~~~~~~ End Sub   ~~~~~~~  Sub_uninstall
(168)     [6] [Nov 20 19:04:09:029] [ansys18]     
(169)     [6] [Nov 20 19:04:09:029] [ansys18]   
(170)     [6] [Nov 20 19:04:09:029] [ansys18]   ~~~~~~ End Loop
(171)     [6] [Nov 20 19:04:09:029] [ansys18]   
(172)     [6] [Nov 20 19:04:09:029] [ansys18]   ~~~~~~~ End Sub   ~~~~~~~  Sub "p:\ansys18\delsub64.ins"
(173)     [6] [Nov 20 19:04:09:029] [ansys18]   
(174)     [2] [Nov 20 19:04:09:029] [ansys18]   Syntax Error in Section: Actions (Command in line 33 origin: p:\ansys18\uninstall64.ins line: 34): EndIf -> expected
(175)     [1] [Nov 20 19:04:09:029] [ansys18] ___________________
(176)     [1] [Nov 20 19:04:09:029] [ansys18] script finished: failed
(177)     [1] [Nov 20 19:04:09:029] [ansys18] 2 errors
Taking into acoount that I have just Ansys v18.2 in my computer, what do you think about these errors? is it related to this issue that I donot have Ansys v18.0 now?
Also about the second error, I have 1 endif for 1 if, but what is the problem?
:oops:
Benutzeravatar
n.wenselowski
Ex-uib-Team
Beiträge: 3194
Registriert: 04 Apr 2013, 12:15

Re: how can use loop for and lists to define different versions of uninstalling a program?

Beitrag von n.wenselowski »

Hi,

the problem with the string expression is my bad I think :lol:

Try this:

Code: Alles auswählen

[Sub_uninstall]
Set $UninstallProgram$ = $InstallDir$ + "\%version%\Uninstall.exe"
if FileExists($UninstallProgram$)
    comment "Uninstall program found, starting uninstall"
    Winbatch_uninstall
    sub_check_exitcode
endif
As for uninstalling check your scripts!


Kind regards

Niko

Code: Alles auswählen

import OPSI
shirin
Beiträge: 7
Registriert: 20 Nov 2017, 12:16

Re: how can use loop for and lists to define different versions of uninstalling a program?

Beitrag von shirin »

Thank you very much, that works. :D
Antworten