Versions
By Thomas_H 2011/11/09 08:56
By Thomas_H 2011/11/16 13:25 Thanks to Karsten K. for informations about incompleted deinstallation.
Tested with opsi 4.0.1
requiredWinstVersion >= 4.10.8.6
By Thomas_H 2011/11/09 08:56
The installation-files can be downloaded at http://www.microsoft.com/downloads/de-de/details.aspx?FamilyID=0a391abd-25c1-4fc0-919f-b21f31ab88b7
Special thanks to: joerg.ludwig for his code, to be found in the Forum which solved the problem of a failed installation when re-installing the OS on a PC.
Tree:
AutoIt3.exe
delsub.ins
dotNetFX.jpg
dotNetFx40_Full_x86_x64.exe
setup.ins
uninstall.ins
[Initial] LogLevel=9 ; Log Errors in Logfile but don't abort: ExitOnError=false ; Show syntax errors in the script: ScriptErrorMessages=on ; Dont trace step by step through the script: TraceMode=off ; let started programs run in front of the winst window StayOnTop=false [Actions] requiredWinstVersion >= "4.10.8.6" DefVar $UninstallProgram32$ DefVar $UninstallProgram64$ DefVar $ProductId$ DefVar $MinimumSpace$ DefVar $InstallDir32$ DefVar $InstallDir64$ DefVar $ExitCode$ DefVar $LicenseRequired$ DefVar $LicenseKey$ DefVar $LicensePool$ DefVar $INST_SystemType$ DefVar $INST_architecture$ DefVar $Version$ DefVar $Inst_Cmd32$ DefVar $Inst_Cmd64$ DefVar $Uninst_Cmd32$ DefVar $Uninst_Cmd64$ DefVar $Inst_Prg$ DefVar $Uninst_Prg$ DefVar $LogDir$ DefVar $opsiadminuser$ DefVar $opsiadminpwd$ Set $INST_SystemType$ = GetSystemType set $INST_architecture$ = GetProductProperty("install_architecture","system specific") 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$ = "dotNetFX" Set $Version$ = "4.0" Set $MinimumSpace$ = "55 MB" ; the path were we find the product after the installation Set $InstallDir32$ = "%Systemroot%\Microsoft.NET\Framework\v4.0.30319\SetupCache\Extended\" Set $InstallDir64$ = "%Systemroot%\Microsoft.NET\Framework64\v4.0.30319\SetupCache\Extended\" Set $LicenseRequired$ = "false" Set $LicensePool$ = "p_" + $ProductId$ Set $Inst_Prg$ = "dotNetFx40_Full_x86_x64.exe" Set $Inst_Cmd32$ = '/passive /norestart' Set $Inst_Cmd64$ = 'NOT NEEDED HERE!' Set $Uninst_Cmd32$ = '/uninstall /x86 /x64 /ia64 /parameterfolder Extended /passive /norestart' Set $Uninst_Cmd64$ = '/uninstall /x86 /x64 /ia64 /parameterfolder Extended /passive /norestart' Set $Uninst_Prg$ = "setup.exe" Set $opsiadminuser$ = "opsiSetupAdmin" Set $opsiadminpwd$ = randomstr ; ---------------------------------------------------------------- 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$ + ".jpg" $ProductId$+" "+$Version$ if FileExists("%ScriptPath%\delsub.ins") comment "Start uninstall sub section" Sub "%ScriptPath%\delsub.ins" endif if $LicenseRequired$ = "true" comment "Licensing required, reserve license and get license key" Sub_get_licensekey endif comment "installing" Message "Copying Setup to Disk..." FilesCopy Message "Installing " + $ProductId$ + " 32 Bit..." comment "Start setup program" DosBatchUserdel DosBatchUseradd DefStringList $res$ Set $res$ = getOutStreamFromSection("ExecWithSetup '%ScriptPath%\AutoIt3.exe' WINST") if count($res$) = "1" DefVar $e$ Set $e$ = takeString(0, $res$) Comment "setup exit code: " + $e$ if ($e$ = "1614") or ($e$ = "3010") ExitWindows /Reboot endif else LogError "Fatal: Setup did not return exit code!" IsFatalError endif DosBatchUserdel ; Ok, let's check, if .Net Framework was installed... if not(FileExists("%systemroot%\Microsoft.NET\Framework\v4.0.30319")) LogError "Fatal: Framework not found!" IsFatalError endif FilesDelete Sub_check_exitcode endif [FilesCopy] copy "%ScriptPath%\dotNetFx40_Full_x86_x64.exe" "$LogDir$" [DosBatchUseradd] net user "$opsiadminuser$" "$opsiadminpwd$" /add net localgroup Administratoren /add "$opsiadminuser$" [DosBatchUserdel] net user "$opsiadminuser$" /delete rmdir /s /q "%ProfileDir%\$opsiadminuser$" [ExecWithSetup] ; http://msdn.microsoft.com/library/ee942965%28v=VS.100%29.aspx ; return exit code via stdout as winst cannot read exit codes from ExecWith $ExitCode = RunAsWait("$opsiadminuser$", @ComputerName, "$opsiadminpwd$", 1, _ '"$LogDir$\$Inst_Prg$" $Inst_Cmd32$') if not @error then ConsoleWrite($exitcode) endif [FilesDelete] delete "$LogDir$/$Inst_Prg$" [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/aa372835(VS.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
[Initial] LogLevel=9 ; Log Errors in Logfile but don't abort: ExitOnError=false ; Show syntax errors in the script: ScriptErrorMessages=on ; Dont trace step by step through the script: TraceMode=off ; let started programs run in front of the winst window StayOnTop=false [Actions] requiredWinstVersion >= "4.10.8.6" DefVar $UninstallProgram32$ DefVar $UninstallProgram64$ DefVar $UninstallProgram32_2$ DefVar $UninstallProgram64_2$ DefVar $LogDir$ DefVar $ExitCode$ DefVar $ProductId$ DefVar $InstallDir32$ DefVar $InstallDir32_2$ DefVar $InstallDir64$ DefVar $InstallDir64_2$ DefVar $LicenseRequired$ DefVar $LicensePool$ DefVar $INST_SystemType$ DefVar $INST_architecture$ DefVar $Uninst_Cmd32$ DefVar $Uninst_Cmd32_2$ DefVar $Uninst_Cmd64$ DefVar $Uninst_Cmd64_2$ DefVar $Uninst_Prg$ Set $INST_SystemType$ = GetSystemType set $INST_architecture$ = GetProductProperty("install_architecture","system specific") Set $LogDir$ = "%SystemDrive%\tmp" ; ---------------------------------------------------------------- ; - Please edit the following values - ; ---------------------------------------------------------------- Set $ProductId$ = "dotNETFx" Set $InstallDir32$ = "%Systemroot%\Microsoft.NET\Framework\v4.0.30319\SetupCache\Extended\" Set $InstallDir32_2$ = "%Systemroot%\Microsoft.NET\Framework\v4.0.30319\SetupCache\Client\" Set $InstallDir64$ = "%Systemroot%\Microsoft.NET\Framework64\v4.0.30319\SetupCache\Extended\" Set $InstallDir64_2$ = "%Systemroot%\Microsoft.NET\Framework\v4.0.30319\SetupCache\Client\" Set $LicenseRequired$ = "false" Set $LicensePool$ = "p_" + $ProductId$ Set $Uninst_Prg$ = "setup.exe" Set $Uninst_Cmd32$ = '/uninstall /x86 /x64 /ia64 /parameterfolder Extended /passive /norestart' Set $Uninst_Cmd32_2$ = '/uninstall /x86 /x64 /parameterfolder Client /passive /norestart' Set $Uninst_Cmd64$ = '/uninstall /x86 /x64 /ia64 /parameterfolder Extended /passive /norestart' Set $Uninst_Cmd64_2$ = '/uninstall /x86 /x64 /parameterfolder Client /passive /norestart' ; ---------------------------------------------------------------- comment "Show product picture" ShowBitmap "%ScriptPath%\" + $ProductId$ + ".jpg" $ProductId$ Message "Uninstalling " + $ProductId$ + " ..." if FileExists("%ScriptPath%\delsub.ins") comment "Start uninstall sub section" Sub "%ScriptPath%\delsub.ins" endif if $LicenseRequired$ = "true" comment "Licensing required, free license used" Sub_free_license endif ExitWindows /Reboot [Sub_free_license] comment "License management is enabled and will be used" comment "Trying to free license used for the product" DefVar $result$ Set $result$ = FreeLicense($LicensePool$) ; If there is an assignment of a license pool to the product, it is possible to use ; Set $result$ = FreeLicense("", $ProductId$) ; ; If there is an assignment of a license pool to a windows software id, it is possible to use ; DefVar $WindowsSoftwareId$ ; $WindowsSoftwareId$ = "..." ; set $result$ = FreeLicense("", "", $WindowsSoftwareId$)
Set $UninstallProgram32$ = $InstallDir32$+"\"+$Uninst_Prg$ Set $UninstallProgram64$ = $InstallDir64$+"\"+$Uninst_Prg$ Set $UninstallProgram32_2$ = $InstallDir32_2$+"\"+$Uninst_Prg$ Set $UninstallProgram64_2$ = $InstallDir64_2$+"\"+$Uninst_Prg$ if (($INST_SystemType$ = "x86 System") and ($INST_architecture$ = "system specific")) or ($INST_architecture$ = "both") or ($INST_architecture$ = "32 only") Message "Uninstalling " + $ProductId$ + " 32 Bit..." if FileExists($UninstallProgram32$) comment "Uninstall program found, starting uninstall" Winbatch_uninstall_32 comment "Removing "+$InstallDir32$ Files_uninstall_32 sub_check_exitcode endif endif if ($INST_SystemType$ = "64 Bit System") and (($INST_architecture$ = "system specific") or ($INST_architecture$ = "both") or ($INST_architecture$ = "64 only")) Message "Uninstalling " + $ProductId$ + " 64 Bit..." if FileExists($UninstallProgram64$) comment "Uninstall program found, starting uninstall" Winbatch_uninstall_64 comment "Removing "+$InstallDir64$ Files_uninstall_64 sub_check_exitcode endif endif [Winbatch_uninstall_32] $UninstallProgram32$ $Uninst_Cmd32$ $UninstallProgram32_2$ $Uninst_Cmd32_2$ [Winbatch_uninstall_64] $UninstallProgram64$ $Uninst_Cmd64$ $UninstallProgram64_2$ $Uninst_Cmd64_2$ [Files_uninstall_32] ; Example for recursively deleting the installation directory (don't forget the trailing backslash): ; delete -sf "$InstallDir32$\" [Files_uninstall_64] ; Example for recursively deleting the installation directory (don't forget the trailing backslash): ; delete -sf "$InstallDir64$\" [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/aa372835(VS.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