Code

source: opsi.opsi-builder/sample/All/CLIENT_DATA/delsub3264.opsiscript @ 19f6c8

Revision 19f6c8, 8.9 KB checked in by geos_one, 2 months ago (diff)

Add Reboot for Broken Installers

  • Property mode set to 100644
Line 
1; Copyright (c) uib gmbh (www.uib.de)
2; This sourcecode is owned by uib gmbh
3; and published under the Terms of the General Public License.
4; credits: http://www.opsi.org/en/credits/
5
6include_append "browserkill.opsiinc"
7
8Set $UninstallProgram32$ = $InstallDir32$ + "\" + $UninstallExecutable32$
9Set $IniFile32$ = $InstallDir32$ + "\opsi-" + $ProductId$ + ".ini"
10
11Set $UninstallProgram64$ = $InstallDir64$ + "\" + $UninstallExecutable64$
12Set $IniFile64$ = $InstallDir64$ + "\opsi-" + $ProductId$ + ".ini"
13
14if (($INST_SystemType$ = "x86 System") and ($INST_architecture$ = "system specific")) or ($INST_architecture$ = "both") or ($INST_architecture$ = "32 only")
15        if FileExists($IniFile32$)
16                Set $OLD_VERSION$ = GetValueFromInifile($IniFile32$,"COMMON","VERSION","")
17                Set $OLD_CREATOR_TAG$ = GetValueFromInifile($IniFile32$,"COMMON","CREATOR_TAG","")
18                Set $OLD_RELEASE$ = GetValueFromInifile($IniFile32$,"COMMON","RELEASE","")
19                Message "Uninstalling " + $ProductId$ + " "+ $OLD_VERSION$ + "-" + $OLD_CREATOR_TAG$ + $OLD_RELEASE$ + " 32 Bit..."
20        else
21                Message "Uninstalling " + $ProductId$ + " 32 Bit..."
22        endif
23
24        if FileExists($IniFile32$)
25                Set $UninstallExecutable32$ = GetValueFromInifile($IniFile32$,"X86","UninstallExecutable32","XXXXXXXX.exe")
26                Set $UninstallProgramOld32$ = $InstallDir32$ + "\" + $UninstallExecutable32$
27                if FileExists($UninstallProgramOld32$)
28                        comment "Uninstall program found, starting uninstall"
29                        Winbatch_uninstall_old_32
30                        sub_check_exitcode
31                endif
32        endif
33        if FileExists($UninstallProgram32$)
34                comment "Uninstall program found, starting uninstall"
35                Winbatch_uninstall_32
36                sub_check_exitcode
37        endif
38
39        if FileExists($IniFile32$)
40                Set $MsiIdOld32$ = GetValueFromInifile($IniFile32$,"X86","MsiId32","{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}")
41                if not (GetRegistryStringValue32("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + $MsiIdOld32$ + "] DisplayName") = "")
42                        comment "Old MSI id " + $MsiIdOld32$ + " found in registry, starting msiexec to uninstall old version"
43                        Winbatch_uninstall_msi_old_32
44                        sub_check_exitcode
45                endif
46        endif
47        if not (GetRegistryStringValue32("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + $MsiId32$ + "] DisplayName") = "")
48                comment "MSI id " + $MsiId32$ + " found in registry, starting msiexec to uninstall"
49                Winbatch_uninstall_msi_32
50                sub_check_exitcode
51        endif
52       
53        ;comment "Kill Web Browser"
54        ;ExecWith_BrowserKill %System%\cscript.exe //b //nologo
55        comment "Delete files"
56        Files_uninstall_32 /32Bit
57        comment "Cleanup registry"
58        Registry_uninstall /32Bit
59endif
60
61if ($INST_SystemType$ = "64 Bit System") and (($INST_architecture$ = "system specific") or ($INST_architecture$ = "both") or ($INST_architecture$ = "64 only"))
62        if FileExists($IniFile64$)
63                Set $OLD_VERSION$ = GetValueFromInifile($IniFile64$,"COMMON","VERSION","")
64                Set $OLD_CREATOR_TAG$ = GetValueFromInifile($IniFile64$,"COMMON","CREATOR_TAG","")
65                Set $OLD_RELEASE$ = GetValueFromInifile($IniFile64$,"COMMON","RELEASE","")
66                Message "Uninstalling " + $ProductId$ + " "+ $OLD_VERSION$ + "-" + $OLD_CREATOR_TAG$ + $OLD_RELEASE$ + " 64 Bit..."
67        else
68                Message "Uninstalling " + $ProductId$ + " 64 Bit..."
69        endif
70
71        if FileExists($IniFile64$)
72                Set $UninstallExecutable64$ = GetValueFromInifile($IniFile64$,"X86_64","UninstallExecutable64","XXXXXXXX.exe")
73                Set $UninstallProgramOld64$ = $InstallDir64$ + "\" + $UninstallExecutable64$
74                if FileExists($UninstallProgramOld64$)
75                        comment "Uninstall program found, starting uninstall"
76                        Winbatch_uninstall_old_64
77                        sub_check_exitcode
78                endif
79        endif
80        if FileExists($UninstallProgram64$)
81                comment "Uninstall program found, starting uninstall"
82                Winbatch_uninstall_64
83                sub_check_exitcode
84        endif
85
86        if FileExists($IniFile64$)
87                Set $MsiIdOld64$ = GetValueFromInifile($IniFile64$,"X86_64","MsiId64","{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}")
88                if not (GetRegistryStringValue64("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + $MsiIdOld64$ + "] DisplayName") = "")
89                        comment "Old MSI id " + $MsiIdOld64$ + " found in registry, starting msiexec to uninstall old version"
90                        Winbatch_uninstall_msi_old_64
91                        sub_check_exitcode
92                endif
93        endif
94        if not (GetRegistryStringValue64("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + $MsiId64$ + "] DisplayName") = "")
95                comment "MSI id " + $MsiId64$ + " found in registry, starting msiexec to uninstall"
96                Winbatch_uninstall_msi_64
97                sub_check_exitcode
98        endif
99       
100        ;comment "Kill Web Browser"
101        ;ExecWith_BrowserKill %System%\cscript.exe //b //nologo
102        comment "Delete files"
103        Files_uninstall_64 /64Bit
104        comment "Cleanup registry"
105        Registry_uninstall /64Bit
106endif
107
108comment "Delete program shortcuts"
109LinkFolder_uninstall
110
111if $Reboot$="1"
112        ExitWindows /ImmediateReboot
113endif
114
115[Winbatch_uninstall_old_32]
116; Choose one of the following examples as basis for program uninstall
117;
118; === Nullsoft Scriptable Install System ================================================================
119; maby better Call as
120; Winbatch_uninstall /WaitforProcessending "Au_.exe" /Timeoutseconds 10
121; "$UninstallProgramOld32$" /S
122;
123; === Inno Setup ========================================================================================
124; "$UninstallProgramOld32$" /silent /norestart /SUPPRESSMSGBOXES /nocancel
125
126[Winbatch_uninstall_32]
127; Choose one of the following examples as basis for program uninstall
128;
129; === Nullsoft Scriptable Install System ================================================================
130; maby better Call as
131; Winbatch_uninstall /WaitforProcessending "Au_.exe" /Timeoutseconds 10
132; "$UninstallProgram32$" /S
133;
134; === Inno Setup ========================================================================================
135; "$UninstallProgram32$" /silent /norestart /SUPPRESSMSGBOXES /nocancel
136
137
138[Winbatch_uninstall_msi_old_32]
139msiexec /x $MsiIdOld32$ /qb-! REBOOT=ReallySuppress
140
141[Winbatch_uninstall_msi_32]
142msiexec /x $MsiId32$ /qb-! REBOOT=ReallySuppress
143
144[Files_uninstall_32]
145; Example for recursively deleting the installation directory (don't forget the trailing backslash):
146;
147; delete -sf "$InstallDir32$\"
148
149[Winbatch_uninstall_old_64]
150; Choose one of the following examples as basis for program uninstall
151;
152; === Nullsoft Scriptable Install System ================================================================
153; maby better Call as
154; Winbatch_uninstall /WaitforProcessending "Au_.exe" /Timeoutseconds 10
155; "$UninstallProgramOld64$" /S
156;
157; === Inno Setup ========================================================================================
158; "$UninstallProgramOld64$" /silent /norestart /SUPPRESSMSGBOXES /nocancel
159
160[Winbatch_uninstall_64]
161; Choose one of the following examples as basis for program uninstall
162;
163; === Nullsoft Scriptable Install System ================================================================
164; maby better Call as
165; Winbatch_uninstall /WaitforProcessending "Au_.exe" /Timeoutseconds 10
166; "$UninstallProgram64$" /S
167;
168; === Inno Setup ========================================================================================
169; "$UninstallProgram64$" /silent /norestart /SUPPRESSMSGBOXES /nocancel
170
171[Winbatch_uninstall_msi_old_64]
172msiexec /x $MsiIdOld64$ /qb-! REBOOT=ReallySuppress
173
174[Winbatch_uninstall_msi_64]
175msiexec /x $MsiId64$ /qb-! REBOOT=ReallySuppress
176
177[Files_uninstall_64]
178; Example for recursively deleting the installation directory:
179;
180; del -sf "$InstallDir64$\"
181
182[Registry_uninstall]
183; Example of deleting a registry key:
184;
185; deletekey [HKEY_LOCAL_MACHINE\Software\$ProductId$]
186
187[LinkFolder_uninstall]
188; Example of deleting a folder from AllUsers startmenu:
189;
190; set_basefolder common_programs
191; delete_subfolder $ProductId$
192;
193; Example of deleting a shortcut from AllUsers desktop:
194;
195; set_basefolder common_desktopdirectory
196; set_subfolder ""
197; delete_element $ProductId$
198
199[Sub_check_exitcode]
200comment "Test for installation success via exit code"
201set $ExitCode$ = getLastExitCode
202; informations to exit codes see
203; http://msdn.microsoft.com/en-us/library/aa372835(VS.85).aspx
204; http://msdn.microsoft.com/en-us/library/aa368542.aspx
205if ($ExitCode$ = "0")
206        comment "Looks good: setup program gives exitcode zero"
207else
208        comment "Setup program gives a exitcode unequal zero: " + $ExitCode$
209        if ($ExitCode$ = "1605")
210                comment "ERROR_UNKNOWN_PRODUCT  1605    This action is only valid for products that are currently installed."
211                comment "Uninstall of a not installed product failed - no problem"
212        else
213                if ($ExitCode$ = "1641")
214                        comment "looks good: setup program gives exitcode 1641"
215                        comment "ERROR_SUCCESS_REBOOT_INITIATED 1641    The installer has initiated a restart. This message is indicative of a success."
216                else
217                        if ($ExitCode$ = "3010")
218                                comment "looks good: setup program gives exitcode 3010"
219                                comment "ERROR_SUCCESS_REBOOT_REQUIRED  3010    A restart is required to complete the install. This message is indicative of a success."
220                        else
221                                logError "Fatal: Setup program gives an unknown exitcode unequal zero: " + $ExitCode$
222                                isFatalError
223                        endif
224                endif
225        endif
226endif
227
Note: See TracBrowser for help on using the repository browser.