Opsi (Open PC Server Integration) est un outil de gestion de clients Windows basé sur un serveur Linux et sous licence AGPLv3 (hors code des modules cofinancés), version modifiée et orientée serveurs de la licence GPLv3. Son code source est la propriété de la société uib gmgh et son représentant en France/Belgique est la société Opensides.
Ses fonctionnalités principales sont :
- Installation automatisée via PXE de systèmes d’exploitation clients Windows par le biais d’une image
- Distribution automatique des logiciels via une connexion agent/serveur
- Intégration automatique des drivers en se basant sur l’ID de ceux-ci
- Inventaires matériels et logiciels
- Dépôts logiciels multiples et décentralisés
Objectif
L’objectif de cet article est l’explication du fonctionnement des scripts opsi-winst ainsi que leur inter-dépendance.
Réalisation
Les scripts Opsi (écrits dans un langage de scripts propre à uib) permettent l’installation, la mise à jour et la désinstallation de logiciels sur le client. Ce processus s’effectue grâce à l’agent Opsi (paquet opsi-client-agent), mais en particulier l’une de ses composantes complémentaires : Opsi Winst (paquet opsi-winst). L’agent Opsi, lors de son installation, a généré un service tournant en tâche de fond appelé opsiclientd. A chaque démarrage du client, ce service effectue une vérification d’éventuelles installations ou mises à jour de logiciels programmées. Si c’est le cas, le partage [opsi_depot] est monté en local sur le client via l’utilisateur pcpatch et l’agent Opsi appelle Opsi Winst qui va exécuter les scripts Opsi dans l’ordre suivant :
Cas d’une installation sur architecture 32 bits
- setup32.ins : appel du script delsub32.ins
- delsub32.ins : désinstallation préalable du produit
- retour au script setup32.ins : installation du produit proprement dite et éventuelle affectation d’une licence
Cas d’une désinstallation sur architecture 32 bits
- uninstall32.ins : appel du script delsub32.ins
- delsub32.ins : désinstallation du produit
- retour au script uninstall32.ins : libération éventuelle de la licence du produit
Dans tous les cas, le script delsub32.ins est appelé afin de désinstaller le produit. Bien évidemment, si le processus de désinstallation du produit n’est pas défini, ce fichier sera immédiatement zappé pour retourner au script setup32.ins dans le cas d’une installation.
Ces scripts Opsi (setup32.ins, delsub32.ins et uninstall32.ins) possèdent des templates à adapter aux besoins et en fonction du logiciel à déployer. Ils sont accessibles de différentes manières :
- Doku officiel Opsi – Opsi Template
- Scripts extraits dans /var/lib/opsi/depot/opsi-template/
- Extraction d’un paquet opsi-template_<version>.opsi disponible sur les dépôts d’uib
La 1ère solution (doku Opsi) peut présenter un retardavec les dernières versions de templates disponibles.
La 2ème solution nécessite un paquet opsi-template mis à jour.
La 3ème solution génère des templates mis à jour régulièment, elle est la solution à privilégier. Il existe deux manières d’extraire les templates depuis le paquet lui-même.
ex :
# file opsi-template_4.0.6-1.opsi opsi-template_4.0.6-1.opsi: ASCII cpio archive (SVR4 with CRC) # mkdir opsi-template ; cd opsi-template # cpio -idv < ../opsi-template_4.0.6-1.opsi CLIENT_DATA.cpio.gz OPSI.cpio.gz 54 blocs # mkdir CLIENT_DATA ; cd CLIENT_DATA # gzip -d < ../CLIENT_DATA.cpio.gz | cpio -idv use_include use_include/delsub_short32.opsiscript use_include/uninstall_short32.opsiscript use_include/setup_short32.opsiscript 3264 3264/delsub3264.opsiscript 3264/setup3264.opsiscript 3264/uninstall3264.opsiscript 32advanced 32advanced/delsub32.opsiscript 32advanced/setup32.opsiscript 32advanced/uninstall32.opsiscript opsi-template.png 64 64/uninstall64.opsiscript 64/delsub64.opsiscript 64/setup64.opsiscript org delsub32.opsiscript login.opsiscript setup32.opsiscript uninstall32.opsiscript 171 blocs # cd .. # mkdir OPSI ; cd OPSI # gzip -d < ../OPSI.cpio.gz | cpio -idv control preinst postinst 15 blocs # cd .. # tree OPSI/ CLIENT_DATA/ OPSI/ ├── control ├── postinst └── preinst CLIENT_DATA/ ├── 3264/ │ ├── delsub3264.opsiscript │ ├── setup3264.opsiscript │ └── uninstall3264.opsiscript ├── 32advanced/ │ ├── delsub32.opsiscript │ ├── setup32.opsiscript │ └── uninstall32.opsiscript ├── 64/ │ ├── delsub64.opsiscript │ ├── setup64.opsiscript │ └── uninstall64.opsiscript ├── delsub32.opsiscript ├── login.opsiscript ├── opsi-template.png ├── org ├── setup32.opsiscript ├── uninstall32.opsiscript └── use_include/ ├── delsub_short32.opsiscript ├── setup_short32.opsiscript └── uninstall_short32.opsiscript 5 directories, 20 files
# file opsi-template_4.0.6-1.opsi # opsi-package-manager -x opsi-template_4.0.6-1.opsi Extracting package source from '/home/adminsys/temp/opsi-template_4.0.6-1.opsi' Extracting archives 100.00% [==================================================] Extracting archive CLIENT_DATA 100.00% [==================================================] Extracting archive OPSI 100.00% [==================================================] # cd opsi-template/ # tree OPSI/ CLIENT_DATA/ OPSI/ ├── control ├── postinst └── preinst CLIENT_DATA/ ├── 3264/ │ ├── delsub3264.opsiscript │ ├── setup3264.opsiscript │ └── uninstall3264.opsiscript ├── 32advanced/ │ ├── delsub32.opsiscript │ ├── setup32.opsiscript │ └── uninstall32.opsiscript ├── 64/ │ ├── delsub64.opsiscript │ ├── setup64.opsiscript │ └── uninstall64.opsiscript ├── delsub32.opsiscript ├── login.opsiscript ├── opsi-template.png ├── org ├── setup32.opsiscript ├── uninstall32.opsiscript └── use_include/ ├── delsub_short32.opsiscript ├── setup_short32.opsiscript └── uninstall_short32.opsiscript 5 directories, 20 files
Les templates de setup32.ins, delsup32.ins et uninstall32.ins sont ici nommés setup32.opsiscript, delsup32.opsiscript et uninstall32.opsiscript.
Les suffixes 32, 64 et 3264 font références aux templates utilisés respectivement pour les architectures 32 bits, 64 bits ou indépendants de l’architecture.
- Les scripts setup32.ins, delsub32.ins et uninstall32.ins appelleront le paramètre Opsi Winst /32Bit
- Les scripts setup64.ins, delsub64.ins et uninstall64.ins appelleront le paramètre Opsi Winst /64Bit
- Les scripts setup3264.ins, delsub3264.ins et uninstall3264.ins appelleront le paramètre Opsi Winst /Sysnative
- Ceci est valable pour les sections [Winbatch_install], [Files_install], [Registry_install], [DOSBatch] et [DOSInAnIcon], mais pas la section [LinkFolder_install]
1. Contenu du template setup32.ins
1.1. setup32.ins avec commentaires
Version 4.11.4.6 du paquet opsi-template.
; 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/en/credits/ [Actions] requiredWinstVersion >= "4.11.4.6" ScriptErrorMessages=off DefVar $MsiId$ DefVar $UninstallProgram$ DefVar $LogDir$ DefVar $ProductId$ DefVar $MinimumSpace$ DefVar $InstallDir$ DefVar $ExitCode$ DefVar $LicenseRequired$ DefVar $LicenseKey$ DefVar $LicensePool$ DefVar $myProperty$ Set $LogDir$ = "%opsiLogDir%" ; ---------------------------------------------------------------- ; - 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$ = "opsi-template" Set $MinimumSpace$ = "1 MB" ; the path were we find the product after the installation Set $InstallDir$ = "%ProgramFiles32Dir%\" Set $LicenseRequired$ = "false" Set $LicensePool$ = "p_" + $ProductId$ ; ---------------------------------------------------------------- if not(HasMinimumSpace ("%SystemDrive%", $MinimumSpace$)) LogError "Not enough space on %SystemDrive%, " + $MinimumSpace$ + " on drive %SystemDrive% needed for " + $ProductId$ isFatalError "No Space" ; Stop process and set installation status to failed else comment "Show product picture" ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$ comment "get property value ....." set $myProperty$ = getProductProperty("dummy_prop", "yes") if $myProperty$ = "yes" comment "myproperty value is yes" else if $myProperty$ = "no" comment "myproperty value is no" else comment "myproperty value must be may_be" endif endif if FileExists("%ScriptPath%\delsub32.ins") comment "Start uninstall sub section" Sub "%ScriptPath%\delsub32.ins" endif Message "Installing " + $ProductId$ + " ..." if $LicenseRequired$ = "true" comment "Licensing required, reserve license and get license key" Sub_get_licensekey endif comment "Start setup program" ChangeDirectory "%SCRIPTPATH%" Winbatch_install Sub_check_exitcode comment "Copy files" Files_install /32Bit comment "Patch Registry" Registry_install /32Bit comment "Create shortcuts" LinkFolder_install endif [Winbatch_install] ; Choose one of the following examples as basis for your installation ; You can use $LicenseKey$ var to pass a license key to the installer ; ; === Nullsoft Scriptable Install System ================================================================ ; "%ScriptPath%\Setup.exe" /S ; ; === MSI package ======================================================================================= ; You may use the parameter PIDKEY=$Licensekey$ ; msiexec /i "%ScriptPath%\some.msi" /l* "$LogDir$\$ProductId$.install_log.txt" /qb-! ALLUSERS=1 REBOOT=ReallySuppress ; ; === InstallShield + MSI===================================================================================== ; Attention: The path to the log file should not contain any whitespaces ; "%ScriptPath%\setup.exe" /s /v" /l* $LogDir$\$ProductId$.install_log.txt /qb-! ALLUSERS=1 REBOOT=ReallySuppress" ; "%ScriptPath%\setup.exe" /s /v" /qb-! ALLUSERS=1 REBOOT=ReallySuppress" ; ; === InstallShield ===================================================================================== ; Create setup.iss answer file by running: setup.exe /r /f1"c:\setup.iss" ; You may use an answer file by the parameter /f1"c:\setup.iss" ; "%ScriptPath%\setup.exe" /s /sms /f2"$LogDir$\$ProductId$.install_log.txt" ; ; === Inno Setup ======================================================================================== ; http://unattended.sourceforge.net/InnoSetup_Switches_ExitCodes.html ; You may create setup answer file by: setup.exe /SAVEINF="filename" ; You may use an answer file by the parameter /LOADINF="filename" ; "%ScriptPath%\setup.exe" /sp- /silent /norestart /nocancel /SUPPRESSMSGBOXES [Files_install] ; Example of recursively copying some files into the installation directory: ; ; copy -s "%ScriptPath%\files\*.*" "$InstallDir$" [Registry_install] ; Example of setting some values of an registry key: ; ; openkey [HKEY_LOCAL_MACHINE\Software\$ProductId$] ; set "name1" = "some string value" ; set "name2" = REG_DWORD:0001 ; set "name3" = REG_BINARY:00 af 99 cd [LinkFolder_install] ; Example of deleting a folder from AllUsers startmenu: ; ; set_basefolder common_programs ; delete_subfolder $ProductId$ ; ; Example of creating an shortcut to the installed exe in AllUsers startmenu: ; ; set_basefolder common_programs ; set_subfolder $ProductId$ ; ; set_link ; name: $ProductId$ ; target:; parameters: ; working_dir: $InstallDir$ ; icon_file: ; icon_index: ; end_link ; ; Example of creating an shortcut to the installed exe on AllUsers desktop: ; ; set_basefolder common_desktopdirectory ; set_subfolder "" ; ; set_link ; name: $ProductId$ ; target: [Sub_get_licensekey] if opsiLicenseManagementEnabled comment "License management is enabled and will be used" comment "Trying to get a license key" Set $LicenseKey$ = demandLicenseKey ($LicensePool$) ; If there is an assignment of exactly one licensepool to the product the following call is possible: ; Set $LicenseKey$ = demandLicenseKey ("", $ProductId$) ; ; If there is an assignment of a license pool to a windows software id, it is possible to use: ; DefVar $WindowsSoftwareId$ ; $WindowsSoftwareId$ = "..." ; Set $LicenseKey$ = demandLicenseKey ("", "", $WindowsSoftwareId$) DefVar $ServiceErrorClass$ set $ServiceErrorClass$ = getLastServiceErrorClass comment "Error class: " + $ServiceErrorClass$ if $ServiceErrorClass$ = "None" comment "Everything fine, we got the license key '" + $LicenseKey$ + "'" else if $ServiceErrorClass$ = "LicenseConfigurationError" LogError "Fatal: license configuration must be corrected" LogError getLastServiceErrorMessage isFatalError else if $ServiceErrorClass$ = "LicenseMissingError" LogError "Fatal: required license is not supplied" isFatalError endif endif endif else LogError "Fatal: license required, but license management not enabled" isFatalError endif [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; parameters: ; working_dir: $InstallDir$ ; icon_file: ; icon_index: 2 ; end_link
1.2. setup32.ins sans les commentaires
Version 4.11.4.6 du paquet opsi-template.
[Actions] requiredWinstVersion >= "4.11.4.6" ScriptErrorMessages=off DefVar $MsiId$ DefVar $UninstallProgram$ DefVar $LogDir$ DefVar $ProductId$ DefVar $MinimumSpace$ DefVar $InstallDir$ DefVar $ExitCode$ DefVar $LicenseRequired$ DefVar $LicenseKey$ DefVar $LicensePool$ DefVar $myProperty$ Set $LogDir$ = "%opsiLogDir%" Set $ProductId$ = "opsi-template" Set $MinimumSpace$ = "1 MB" Set $InstallDir$ = "%ProgramFiles32Dir%\" Set $LicenseRequired$ = "false" Set $LicensePool$ = "p_" + $ProductId$ if not(HasMinimumSpace ("%SystemDrive%", $MinimumSpace$)) LogError "Not enough space on %SystemDrive%, " + $MinimumSpace$ + " on drive %SystemDrive% needed for " + $ProductId$ isFatalError "No Space" else comment "Show product picture" ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$ comment "get property value ....." set $myProperty$ = getProductProperty("dummy_prop", "yes") if $myProperty$ = "yes" comment "myproperty value is yes" else if $myProperty$ = "no" comment "myproperty value is no" else comment "myproperty value must be may_be" endif endif if FileExists("%ScriptPath%\delsub32.ins") comment "Start uninstall sub section" Sub "%ScriptPath%\delsub32.ins" endif Message "Installing " + $ProductId$ + " ..." if $LicenseRequired$ = "true" comment "Licensing required, reserve license and get license key" Sub_get_licensekey endif comment "Start setup program" ChangeDirectory "%SCRIPTPATH%" Winbatch_install Sub_check_exitcode comment "Copy files" Files_install /32Bit comment "Patch Registry" Registry_install /32Bit comment "Create shortcuts" LinkFolder_install endif [Winbatch_install] [Files_install] [Registry_install] [LinkFolder_install] [Sub_get_licensekey] if opsiLicenseManagementEnabled comment "License management is enabled and will be used" comment "Trying to get a license key" Set $LicenseKey$ = demandLicenseKey ($LicensePool$) DefVar $ServiceErrorClass$ set $ServiceErrorClass$ = getLastServiceErrorClass comment "Error class: " + $ServiceErrorClass$ if $ServiceErrorClass$ = "None" comment "Everything fine, we got the license key '" + $LicenseKey$ + "'" else if $ServiceErrorClass$ = "LicenseConfigurationError" LogError "Fatal: license configuration must be corrected" LogError getLastServiceErrorMessage isFatalError else if $ServiceErrorClass$ = "LicenseMissingError" LogError "Fatal: required license is not supplied" isFatalError endif endif endif else LogError "Fatal: license required, but license management not enabled" isFatalError endif [Sub_check_exitcode] comment "Test for installation success via exit code" set $ExitCode$ = getLastExitCode 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
1.3. setup32.ins dans les grandes lignes
[Actions] Section 1
-
Définition des variables
Affectation des variables
Teste espace requis à l'installation sur le client
Appel du fichier delsub32.ins pour désinstallation préalable
Appel des autres sections imbriquées
-
Vérification et affectation de la licence depuis le pool défini
-
Installation silencieuse
-
Code retour de Winbatch_install
-
Copie des fichiers
-
Ajout d'une ou plusieurs entrées dans la base de registres
-
Ajout d'une entrée au menu Démarrer
Ajout d'une icône sur le bureau Public
2. Contenu du template uninstall32.ins
2.1. uninstall32.ins avec commentaires
Version 4.11.4.6 du paquet opsi-template.
; 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/en/credits/ [Actions] requiredWinstVersion >= "4.11.4.6" ScriptErrorMessages=off DefVar $MsiId$ DefVar $UninstallProgram$ DefVar $LogDir$ DefVar $ExitCode$ DefVar $ProductId$ DefVar $InstallDir$ DefVar $LicenseRequired$ DefVar $LicensePool$ Set $LogDir$ = "%opsiLogDir%" ; ---------------------------------------------------------------- ; - Please edit the following values - ; ---------------------------------------------------------------- Set $ProductId$ = "opsi-template" Set $InstallDir$ = "%ProgramFiles32Dir%\" Set $LicenseRequired$ = "false" Set $LicensePool$ = "p_" + $ProductId$ ; ---------------------------------------------------------------- comment "Show product picture" ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$ Message "Uninstalling " + $ProductId$ + " ..." if FileExists("%ScriptPath%\delsub32.ins") comment "Start uninstall sub section" Sub "%ScriptPath%\delsub32.ins" endif if $LicenseRequired$ = "true" comment "Licensing required, free license used" Sub_free_license endif [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$)
2.2. uninstall32.ins sans les commentaires
Version 4.11.4.6 du paquet opsi-template.
[Actions] requiredWinstVersion >= "4.11.4.6" ScriptErrorMessages=off DefVar $MsiId$ DefVar $UninstallProgram$ DefVar $LogDir$ DefVar $ExitCode$ DefVar $ProductId$ DefVar $InstallDir$ DefVar $LicenseRequired$ DefVar $LicensePool$ Set $LogDir$ = "%opsiLogDir%" Set $ProductId$ = "opsi-template" Set $InstallDir$ = "%ProgramFiles32Dir%\" Set $LicenseRequired$ = "false" Set $LicensePool$ = "p_" + $ProductId$ comment "Show product picture" ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$ Message "Uninstalling " + $ProductId$ + " ..." if FileExists("%ScriptPath%\delsub32.ins") comment "Start uninstall sub section" Sub "%ScriptPath%\delsub32.ins" endif if $LicenseRequired$ = "true" comment "Licensing required, free license used" Sub_free_license endif [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$)
2.3. uninstall32.ins dans les grandes lignes
[Actions] Section 1
-
Définition des variables
Affectation des variables
Appel du fichier delsub32.ins pour désinstallation
Appel des autres sections imbriquées
-
Libération de la licence utilisée dans le pool défini
3. Contenu du template delsub32.ins
3.1. delsub32.ins avec commentaires
Version 4.11.4.6 du paquet opsi-template.
; 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/en/credits/ Set $MsiId$ = '{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}' Set $UninstallProgram$ = $InstallDir$ + "\uninstall.exe" Message "Uninstalling " + $ProductId$ + " ..." if FileExists($UninstallProgram$) comment "Uninstall program found, starting uninstall" Winbatch_uninstall sub_check_exitcode endif if not (GetRegistryStringValue32("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + $MsiId$ + "] DisplayName") = "") comment "MSI id " + $MsiId$ + " found in registry, starting msiexec to uninstall" Winbatch_uninstall_msi sub_check_exitcode endif comment "Delete files" Files_uninstall /32Bit comment "Cleanup registry" Registry_uninstall /32Bit comment "Delete program shortcuts" LinkFolder_uninstall [Winbatch_uninstall] ; Choose one of the following examples as basis for program uninstall ; ; === Nullsoft Scriptable Install System ================================================================ ; maybe better called as ; Winbatch_uninstall /WaitforProcessending "Au_.exe" /Timeoutseconds 10 ; "$UninstallProgram$" /S ; ; === Inno Setup ======================================================================================== ; "$UninstallProgram$" /silent /norestart /SUPPRESSMSGBOXES /nocancel [Winbatch_uninstall_msi] msiexec /x $MsiId$ /qb-! REBOOT=ReallySuppress [Files_uninstall] ; Example for recursively deleting the installation directory: ; ; del -sf "$InstallDir$\" [Registry_uninstall] ; Example of deleting a registry key: ; ; deletekey [HKEY_LOCAL_MACHINE\Software\$ProductId$] [LinkFolder_uninstall] ; Example of deleting a folder from AllUsers startmenu: ; ; set_basefolder common_programs ; delete_subfolder $ProductId$ ; ; Example of deleting a shortcut from AllUsers desktop: ; ; set_basefolder common_desktopdirectory ; set_subfolder "" ; delete_element $ProductId$ [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
3.2. delsub32.ins sans les commentaires
Version 4.11.4.6 du paquet opsi-template.
Set $MsiId$ = '{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}' Set $UninstallProgram$ = $InstallDir$ + "\uninstall.exe" Message "Uninstalling " + $ProductId$ + " ..." if FileExists($UninstallProgram$) comment "Uninstall program found, starting uninstall" Winbatch_uninstall sub_check_exitcode endif if not (GetRegistryStringValue32("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + $MsiId$ + "] DisplayName") = "") comment "MSI id " + $MsiId$ + " found in registry, starting msiexec to uninstall" Winbatch_uninstall_msi sub_check_exitcode endif comment "Delete files" Files_uninstall /32Bit comment "Cleanup registry" Registry_uninstall /32Bit comment "Delete program shortcuts" LinkFolder_uninstall [Winbatch_uninstall] [Winbatch_uninstall_msi] msiexec /x $MsiId$ /qb-! REBOOT=ReallySuppress [Files_uninstall] [Registry_uninstall] [LinkFolder_uninstall] [Sub_check_exitcode] comment "Test for installation success via exit code" set $ExitCode$ = getLastExitCode 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
2.3. delsub32.ins dans les grandes lignes
Affectation des variables définies mais non affectées dans setup32.ins ou uninstall32.ins Appel des autres sections imbriquées [Winbatch_uninstall] Section 1
-
Désinstallation par l'exécutable de désinstallation lié au produit
-
Désinstallation par msiexec
-
Code retour de Winbatch_uninstall ou Winbatch_uninstall_msi
-
Suppression récursive du dossier d'installation ou de fichiers
-
Suppression d'entrées dans la base de registres
-
Suppression de l'entrée du menu Démarrer
Suppression de l'icône du bureau Public
Aller plus loin
Références