wackou

Install new version of software

Feb 6th, 2016
1,839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 6.18 KB | None | 0 0
  1. REM Script pour mettre à jour un logiciel
  2. REM Test si OS 32/64 puis test la présence de fichier, si oui alors on lance le processus de desinstallation puis installation de la nouvelle version
  3. REM Enregistrement des DLL du logiciel
  4. REM Wackou
  5. REM www.wackou.com
  6. @echo off
  7. cls
  8. REM Initilisation variables
  9. REM Obtention de la date, indépendamment de la langue du poste
  10. FOR /f %%a in ('WMIC OS GET LocalDateTime ^| find "."') DO set DTS=%%a
  11. set DATE=%DTS:~0,4%-%DTS:~4,2%-%DTS:~6,2%_%DTS:~8,2%-%DTS:~10,2%
  12. REM Chemin où se trouve les fichiers
  13. set FOLDER=\\dc1.domain.local\software
  14. REM Fichier de log, format COMPUTER_DOMAIN_USERNAME_20160119_15-31-14.log
  15. set LOG_FILE=%COMPUTERNAME%_%USERDOMAIN%_%USERNAME%_%DATE%.log
  16. REM Dossier où les logs seront enregistrés
  17. set LOG_FOLDER=%FOLDER%\Logs
  18. REM Kit installation 32 Bits et 64 Bits
  19. set INSTALL64=%FOLDER%\Setup\install64
  20. set INSTALL32=%FOLDER%\Setup\install32
  21. REM Chemin de .DLL
  22. set DLL=%FOLDER%\Setup\DLL.dll
  23. REM Dossier contenant des fichiers de traduction
  24. set FILES=%FOLDER%\Setup\Files
  25. REM ID package MSI de l'ancienne et la nouvelle version
  26. set ID_OLD_V={436F3D0A-3994-4883-B5C8-761B9071B7CA}
  27. set ID_NEW_V={451A01D7-7124-4F03-9E8D-B3B387D39F7F}
  28. REM Dossiers installation OS 64 Bits
  29. set DIR64=%ProgramFiles%\software\folder
  30. set DIR32=%ProgramFiles(x86)%\software\folder
  31. REM Dossier installation OS 32 Bits
  32. set DIR=%DIR64%
  33.  
  34. REM Debut du programme
  35. echo Script starting at %time:~0,2%-%time:~3,2%-%time:~6,2% >> "%LOG_FOLDER%\%LOG_FILE%"
  36. REM Verification si 32 Bits ou 64 Bits
  37. if "%PROCESSOR_ARCHITECTURE%" == "x86" (
  38.     echo System is 32 bits >> "%LOG_FOLDER%\%LOG_FILE%"
  39. goto CHK32
  40. ) else (
  41.     echo System is 64 bits >> "%LOG_FOLDER%\%LOG_FILE%"
  42. goto CHK64
  43. )
  44. REM Verification version installée
  45. :CHK64
  46. if exist "%DIR32%\file1.tlb" (
  47.     if exist "%DIR32%\file2.tlb" (
  48.         if exist "%DIR64%\file1.tlb" (
  49.             if exist "%DIR64%\file2.tlb" (
  50.             REM Si tous les tests sont OK, alors c'est la version 64 bits qui est présente
  51.             echo "File1 (32/64 Bits) and File2 (32/64 Bits) found" >> "%LOG_FOLDER%\%LOG_FILE%"
  52.             goto INST64
  53.             )
  54.         )
  55.     )
  56. )
  57. goto NTD
  58. :CHK32
  59. if exist "%DIR%\file1.tlb" (
  60.     if exist "%DIR%\file2.tlb" (
  61.             REM Si tous les tests sont OK, alors c'est la version 32 bits qui est présente
  62.             echo "File1 (32 Bits) and File2 (32 Bits) found" >> "%LOG_FOLDER%\%LOG_FILE%"
  63.             goto INST32
  64.     )
  65. )
  66. goto NTD
  67. REM Installation 64 Bits
  68. :INST64
  69. echo Starting to uninstall old version (64 Bits) >> "%LOG_FOLDER%\%LOG_FILE%"
  70. %windir%\System32\msiexec.exe /x %ID_OLD_V% /quiet
  71. echo Cleaning folder 32 Bits and 64 Bits >> "%LOG_FOLDER%\%LOG_FILE%"
  72. DEL "%DIR32%\*.*" /F /Q
  73. DEL "%DIR64%\*.*" /F /Q
  74. echo Starting to install new version (64 Bits) >> "%LOG_FOLDER%\%LOG_FILE%"
  75. %windir%\System32\msiexec.exe /i "%INSTALL64%\Setup_Client.msi" /quiet
  76. if not exist "%ProgramFiles%\software" mkdir "%ProgramFiles%\software" >> "%LOG_FOLDER%\%LOG_FILE%"
  77. if not exist "%ProgramFiles%\software\folder" mkdir "%ProgramFiles%\software\folder" >> "%LOG_FOLDER%\%LOG_FILE%"
  78. echo Copy %DLL% to %DIR32% >> "%LOG_FOLDER%\%LOG_FILE%"
  79. %windir%\System32\xcopy.exe "%DLL%" "%DIR32%" /h /c /k /q >> "%LOG_FOLDER%\%LOG_FILE%"
  80. echo Copy %FILES% to %DIR32% >> "%LOG_FOLDER%\%LOG_FILE%"
  81. %windir%\System32\xcopy.exe "%FILES%" "%DIR32%" /h /c /k /q /y /s >> "%LOG_FOLDER%\%LOG_FILE%"
  82. echo Copy %DIR32% to %DIR64% >> "%LOG_FOLDER%\%LOG_FILE%"
  83. %windir%\System32\xcopy.exe "%DIR32%" "%DIR64%" /h /e /c /k /q >> "%LOG_FOLDER%\%LOG_FILE%"
  84. "%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\regasm.exe" "%DIR64%\DLL.dll" /codebase /silent >> "%LOG_FOLDER%\%LOG_FILE%"
  85. "%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\regasm.exe" "%DIR32%\DLL.dll" /codebase /silent >> "%LOG_FOLDER%\%LOG_FILE%"
  86. "%SystemRoot%\Microsoft.NET\Framework64\v2.0.50727\regasm.exe" "%DIR64%\DLL2.dll" /codebase /silent >> "%LOG_FOLDER%\%LOG_FILE%"
  87. "%SystemRoot%\Microsoft.NET\Framework64\v2.0.50727\regasm.exe" "%DIR32%\DLL2.dll" /codebase /silent >> "%LOG_FOLDER%\%LOG_FILE%"
  88. "%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\regasm.exe" "%DIR64%\DLL3.dll" /codebase /silent >> "%LOG_FOLDER%\%LOG_FILE%"
  89. "%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\regasm.exe" "%DIR32%\DLL3.dll" /codebase /silent >> "%LOG_FOLDER%\%LOG_FILE%"
  90. REM Creation du fichier d'information pour les utilisateurs
  91. echo New version has been installed >> "%DIR32%\000.txt"
  92. echo New version has been installed >> "%DIR64%\000.txt"
  93. goto END
  94. REM Installation 32 Bits
  95. :INST32
  96. echo Starting to uninstall old version (32 Bits) >> "%LOG_FOLDER%\%LOG_FILE%"
  97. %windir%\System32\msiexec.exe /x %ID_OLD_V% /quiet
  98. echo Cleaning folder 32 Bits >> "%LOG_FOLDER%\%LOG_FILE%"
  99. REM Provoque une erreur en interactif car le dossier est déjà supprimé par la desinstallation
  100. REM DEL "%DIR%\*.*" /F /Q
  101. echo Starting to install new version (32 Bits) >> "%LOG_FOLDER%\%LOG_FILE%"
  102. %windir%\System32\msiexec.exe /i "%INSTALL32%\Setup_Client.msi" /quiet
  103. echo Copy %DLL% to %DIR% >> "%LOG_FOLDER%\%LOG_FILE%"
  104. %windir%\System32\xcopy.exe "%DLL%" "%DIR%" /h /c /k /q >> "%LOG_FOLDER%\%LOG_FILE%"
  105. echo Copy %FILES% to %DIR% >> "%LOG_FOLDER%\%LOG_FILE%"
  106. %windir%\System32\xcopy.exe "%FILES%" "%DIR%" /h /c /k /q /y /s >> "%LOG_FOLDER%\%LOG_FILE%"
  107. "%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\regasm.exe" "%DIR%\DLL.dll" /codebase /silent >> "%LOG_FOLDER%\%LOG_FILE%"
  108. "%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\regasm.exe" "%DIR%\DLL2.dll" /codebase /silent >> "%LOG_FOLDER%\%LOG_FILE%"
  109. REM Creation du fichier d'information pour les utilisateurs
  110. echo New version has been installed >> "%DIR%\000.txt"
  111. goto END
  112. :NTD
  113. echo Nothing to do >> "%LOG_FOLDER%\%LOG_FILE%"
  114. REM Test si nouvelle version installée
  115. for /f "tokens=2*" %%a in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%ID_NEW_V%" /v displayversion 2^>nul') do echo Version is %%b (New) >> "%LOG_FOLDER%\%LOG_FILE%"
  116. REM Test si ancienne version installée
  117. for /f "tokens=2*" %%a in ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%ID_OLD_V%" /v displayversion 2^>nul') do echo Version is %%b (Old) >> "%LOG_FOLDER%\%LOG_FILE%"
  118. goto END
  119. :END
  120. echo Script ending at %time:~0,2%-%time:~3,2%-%time:~6,2% >> "%LOG_FOLDER%\%LOG_FILE%"
Advertisement
Add Comment
Please, Sign In to add comment