home *** CD-ROM | disk | FTP | other *** search
/ ftp2.jacobs.com / 2015.02.ftp2.jacobs.com.tar / ftp2.jacobs.com / altiris.exe / Re-InstallAltiris.cmd < prev    next >
OS/2 REXX Batch file  |  2010-08-17  |  15KB  |  198 lines

  1. @ECHO OFF||                    :: Turns off echo so output is limited in DOS window.
  2. COLOR 07||                    :: Sets DOS window to default color schima.
  3. REM ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  4. REM :     File name: Re-InstallAltiris.cmd                                       :
  5. REM : Originated by: Chad Ellis                                                  :
  6. REM :         EMail: Chad.Ellis@Jacobs.com                                       :
  7. REM :----------------------------------------------------------------------------:
  8. REM :Current Author: XXXX XXXXXX As of XX/XX/XX until present                    :
  9. REM :         Phone: (XXX) XXX-XXXX                                              :
  10. REM :         EMail: XXXX.XXXXX@Jacobs.com                                       :
  11. REM :----------------------------------------------------------------------------:
  12. REM :       DO NOT EDIT THIS FILE WITHOUT INFORMING THE CURRENT AUTHOR(S)        :
  13. REM :                             AS LISTED ABOVE                                :
  14. REM :----------------------------------------------------------------------------:
  15. REM :       Purpose: Uninstall all Symantec Management Agents than Install SMA to:
  16. REM :                local Notification Server.                                  :
  17. REM :                - Add NS fully qualified name to end of this batch file when:
  18. REM :                  calling it to force the install to a different NS.        :
  19. REM :                  Example:                                                  :
  20. REM :                          CALL Re-InstallAltiris.bat EndpointNS15.jacobs.com: 
  21. REM :                                                                            :
  22. REM :     Frequency: Once or as many times you want to re-install SMA.           :
  23. REM :    Invocation: Run batch file directly.                                    :
  24. REM :     Arguments: ...                                                         :
  25. REM :      Switches: ...                                                         :
  26. REM : Special Logic: ...                                                         :
  27. REM : Special Notes: ...                                                         : 
  28. REM : File Location: ...                                                         :
  29. REM :  Color Schima: Use colors to better define window messages.                :
  30. REM :                     Install = Color 70          Default = Color 07         :
  31. REM :                InstallError = Color 74            Error = Color 0C         :
  32. REM :              InstallSuccess = Color 72          Success = Color 0A         :
  33. REM :              InstallMessage = Color 71          Message = Color 0F         :
  34. REM :              InstallWarning = Color 7E          Warning = Color 0E         :
  35. REM :----------------------------------------------------------------------------:
  36. REM : MMDDYY (ver x.x.x)    V E R S I O N    1 . 0 1         By Author Chad Ellis:
  37. REM :----------------------------------------------------------------------------:
  38. REM : 120104 Initial Release ...                                                 :
  39. REM : 020806 (v6.0.1508) Updated Altiris agent to version 6.0.1508               :
  40. REM : 021506 (v6.0.1508.2) Added better error detection and messages to user     :
  41. REM : 060906 (v6.0.2348) Updated Altiris agent to version 6.0.2348               :
  42. REM : 122006 (v6.0.2348.2) Added new Uninstall Routene.                          :
  43. REM : 072707 (v6.0.2348.3) changed LEIMAN02 to AltirisNS4.                       :
  44. REM : 082107 (v6.0.2386) Program updated to the latest agent.                    :
  45. REM : 021108 (v6.0.2386b) Now supports NS6                                       :
  46. REM : 011209 (v6.0.2394) Updated agent and now supports NS7                      :
  47. REM : 121709 (v7.0.3599) Updated agent to v7 using Endpoint alias. Changed name  :
  48. REM :        Altiris to Symantec Management Agent                                :
  49. REM : 031610 (v7.0.438) Added :438 to "http://%NSFQDN%:438/Altiris"              :
  50. REM : 062210 (v7.0.7436) Created nuclear option which completely removes all     :
  51. REM :        Altiris and Symantec Endpoint products before re-installing.        :
  52. REM : 070610 (v7.0.7436.2) Allows for %1 to imput new name for NS. (see above    :
  53. REM :                      purpose.)                                             :
  54. REM : 070810 (v7.0.7436.3) Forces Software Management Solution Agent to install. :
  55. REM : 072910 (v7.0.7436.4) Added ability to read in switches.                    :
  56. REM : 073010 (v7.0.7436.5) Added CPU Throttling ablity.                          :
  57. REM : 080210 (V7.0.7436.6) Added Splash screen so if this batch file is kicked   :
  58. REM :        off more than once, it will detect it and end.                      :
  59. REM : 080410 (v6.0.2403) Updated script to re-install to latest NS v6 agent.     :
  60. REM : 081610 (v6.0.2403.2) Modified to work in Windows 2000 environment.         :
  61. REM : 081710 (v6.0.2403.3) Removed "Splash screen" and replaced with WINMSG.exe  :
  62. REM :         (Splash screen didn't work on machines without .net 2.0.)          :
  63. REM ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  64.  
  65. :: #------------------------------------------------------------------------#
  66. :: #----- BEGIN "Global Settings"                                      -----#
  67. SET SV=6.0.2403.3||                            :: Set Script Version (SV) variable for Virtual Standardized Office (VSO)
  68.  
  69.     :: #- Display the following message in the title bar.
  70. TITLE Re-installing Symantec Management Agent version %SV%||        :: Title given to this script file.
  71.  
  72.     :: #- Temporarily set %SystemRoot% and System32 folders as primary folders in %Path% (Discovered 3rd party programs setting their folders as primary and then they name their .exe same name as MS OS such as Oracle has their own version of Find.exe which doesn't work like MS Find.exe. So any batch file trying to call find.exe will fail.)
  73. SET Path=%SystemRoot%;%SystemRoot%\System32;%Path%
  74.  
  75.     :: #- Detect OS and set new variables to identify OS.
  76. SET Processor|FIND "64">NUL&&        SET BIT=64||        REM General 64 BIT OS
  77. VER|FIND /I "6001">NUL &&         SET OSVER=Vista64||    REM Operating system is Vista 64 bit.
  78. VER|FIND /I "6000">NUL &&         SET OSVER=Vista32||    REM Operating system is Vista 32 bit.
  79. VER|FIND /I "5.2">NUL &&        SET OSver=23||        REM Operating System is windows 2003
  80. VER|FIND /I "XP">NUL &&            SET OSver=XP||        REM Operating System is windows XP
  81. VER|FIND /I "Windows 2000">NUL &&    SET OSver=2K||        REM Operating System is Windows 2000
  82. VER|FIND /I "NT">NUL &&            SET OSver=NT||        REM Operating System is Windows NT 4.0
  83.  
  84.     :: #- Reports Directory
  85. SET NetworkReportsDir=\\oakman07\storage\Temp\Upload\Capture Agents Installed|| :: Network directory where reports are copied up too. (Centralization)
  86.  
  87.     :: #- Set Date variables for Day (spelled out), Month, Day (time), Year
  88. FOR /F "tokens=1,2,3,4 delims=/ " %%i IN ('DATE /T') DO (set Day=%%i&& set MM=%%j&& SET DD=%%k&& SET YY=%%l)
  89.  
  90.     :: #- Set time variables for Hr, Min, AM or PM
  91. FOR /F "tokens=1,2,3,4 delims=: " %%i IN ('Time /T') DO (set Hr=%%i&& set Min=%%j&& SET AMPM=%%k)
  92.  
  93.     :: #- If temp directory is not set, set it. If not, this batch file may fail.
  94. SET TempDir=%Temp%||                            :: Default temp directory of the OS.
  95. IF NOT EXIST "%Temp%" SET TempDir=%SystemDrive%\temp\apps||        :: If no temp directory exists, then set it.
  96. IF NOT EXIST "%TempDir%" MD "%TempDir%"||                :: Temp directory must exist or this script file may bomb out
  97.  
  98.     :: #- Check if Re-install program is already running. If so, skip to the end (NS v7 Managed Software Solution causes re-install program to run multiple times while it uninstalls itself. If Popup is present, then skip to the end and don't run again.)
  99. :CheckIfRunning
  100.    PSLIST | FIND /I "WINMSG" >NUL                    && ECHO ... Re-Install program already running.&& Timeout 15 && GOTO END
  101.    IF NOT "%OSver%"=="2K" TaskList | FIND /I "WINMSG" >NUL        && ECHO ... Re-Install program already running.&& Timeout 15 && GOTO END
  102.    PSLIST | FIND /I "Uninstall-SM-Agents" >NUL                && ECHO ... Re-Install program already running.&& Timeout 15 && GOTO END
  103.    IF NOT "%OSver%"=="2K" TaskList | FIND /I "Uninstall-SM-Agents" >NUL    && ECHO ... Re-Install program already running.&& Timeout 15 && GOTO END
  104.  
  105. :ThrottleCPU
  106.    CALL ThrottleCPU.cmd
  107.  
  108. :ReadSwitches
  109.     :: #- Set default variables and read in %1 to convert input data into appropriate variables (Look at batch file for more details)
  110.    CALL DefaultsAndSwitches.cmd %1 %2 %3 %4 %5 %6 %7 %8 %9
  111.  
  112. :StartPopup
  113.     :: #- Show popup to let this batch file and any users viewing the install that the install happening.
  114.    START WINMSG -t "Re-install Altiris Agent v%AgentVersion% to %NSFQDN%" -m "                Jacobs IT is re-installing your Altiris agent.\n\n                               Please stand by ... \n\n (This window should close automatically when install is complete.)" -c SystemModal,Information
  115.  
  116. CLS||                                    :: Clear screen before continuing.
  117. GOTO Pre
  118. :: #----- END "Global Settings"                                        -----#
  119. :: #------------------------------------------------------------------------#
  120.  
  121. :: #------------------------------------------------------------------------#
  122. :: #----- BEGIN "Pre-Section"                                          -----#
  123. :Pre
  124.  
  125.     :: #- Detect if Altiris is installed
  126.    ECHO Checking to see if Altiris is installed
  127.    REGv1 Query "HKLM\Software\Altiris\Altiris Agent\InstallDir" | FIND /I "Altiris" >NUL && ECHO Altiris is installed && FOR /F "tokens=2*" %%i IN ('REGv1 Query "HKLM\Software\Altiris\Altiris Agent\InstallDir"') DO (SET AltirisDir=%%j)|| ECHO Altiris is NOT installed
  128.    ECHO.
  129.  
  130. :RemoveAgent
  131.    COLOR 7E||                                :: Change color of DOS screen so user knows it is uninstalling.
  132.    ECHO Un-installing All Symantec Management Agents.
  133.    ECHO.
  134.    ECHO Please stand by ...
  135.    CALL Uninstall-SM-Agents.exe
  136.    ECHO.
  137.  
  138.     :: Double check if local Altiris folder exists ... if so rename it.
  139.    IF EXIST "%AltirisDir%" (ECHO ... Renaming "%AltirisDir%" to "Altiris Agent_%Day%%MM%-%DD%-%YY% %HR%-%Min% %AMPM%" && RENAME "%AltirisDir%" "Altiris Agent_%Day%%MM%-%DD%-%YY% %HR%-%Min% %AMPM%") && ECHO Renamed Successfully! && ECHO.
  140. GOTO Main
  141. :: #----- END "Pre-Section"                                            -----#
  142. :: #------------------------------------------------------------------------#
  143.  
  144.  
  145. :: #------------------------------------------------------------------------#
  146. :: #----- BEGIN "Main Section"                                         -----#
  147. :Main
  148.  
  149.     :: #- Install Symantec Management Agent
  150.    Color 70||                                :: Change color of DOS screen so user knows an install is happening.
  151.    ECHO Install the following Agents to Notification Server "%NSFQDN%"
  152. REM   IF "%AltirisDir%"=="" (CALL AeXNSC.exe /Start /install ns=%NSFQDN% nsweb="http://%NSFQDN%:438/Altiris" -s && ECHO ... Symantec Management Agent installed successfully!) ELSE (CALL AeXNSC.exe /Start /install /path="%AltirisDir%"  ns=%NSFQDN% nsweb="http://%NSFQDN%:438/Altiris" -s && ECHO ... Symantec Management Agent installed successfully!)
  153.    IF "%AltirisDir%"=="" (GOTO NoAltirisDir) ELSE (GOTO YesAltirisDir)
  154.  
  155. :YesAltirisDir
  156.    CALL AeXNSC.exe /Start /install /path="%AltirisDir%"  ns=%NSFQDN% nsweb="http://%NSFQDN%:438/Altiris" -s && ECHO ... Symantec Management Agent installed successfully!&& ECHO %Day% %MM%-%DD%-%YY% %HR%^:%Min% %AMPM% ... Symantec Management Agent version %AgentVersion% successfully installed on %ComputerName% >> "%NetworkReportsDir%\%ComputerName%-Agent Install Report.log" || ECHO %Day% %MM%-%DD%-%YY% %HR%^:%Min% %AMPM% ... Symantec Management Agent version %AgentVersion% failed to install on %ComputerName% >> "%NetworkReportsDir%\%ComputerName%-Agent Install Report.log"
  157. GOTO SubAgents
  158.  
  159. :NoAltirisDir
  160.    CALL AeXNSC.exe /Start /install ns=%NSFQDN% nsweb="http://%NSFQDN%:438/Altiris" -s && ECHO ... Symantec Management Agent installed successfully! && ECHO %Day% %MM%-%DD%-%YY% %HR%^:%Min% %AMPM% ... Symantec Management Agent version %AgentVersion% successfully installed on %ComputerName% >> "%NetworkReportsDir%\%ComputerName%-Agent Install Report.log" || ECHO %Day% %MM%-%DD%-%YY% %HR%^:%Min% %AMPM% ... Symantec Management Agent version %AgentVersion% failed to install on %ComputerName% >> "%NetworkReportsDir%\%ComputerName%-Agent Install Report.log"
  161. GOTO SubAgents
  162.  
  163. :SubAgents
  164.     :: #- Install "Software Management Solution Agent"
  165. REM   CALL msiexec.exe /i "Software Management Solution Agent_7_0_rev1.msi" /QN
  166. GOTO Post
  167. :: #----- END "Main Section"                                           -----#
  168. :: #------------------------------------------------------------------------#
  169.  
  170. :: #------------------------------------------------------------------------#
  171. :: #----- BEGIN "Post Section"                                         -----#
  172. :Post
  173.  
  174.     :: #- Check to see if Symantec Management Agent has been installed. Let user know if agent installed correctly.
  175.    ECHO.
  176.    CALL "Capture Agents Installed.exe"
  177.  
  178.     :: #- Add/Update registry to let OS/Altiris know machine was "re-installed".
  179.    REGv1 ADD "HKLM\Software\Jacobs\Symantec\Symantec Management Agent\AgentCleanupVersion=%AgentVersion%">NUL
  180.    REGv1 UPDATE "HKLM\Software\Jacobs\Symantec\Symantec Management Agent\AgentCleanupVersion=%AgentVersion%">NUL
  181.  
  182.     :: #- Now the install is complete, remove Popup screen.
  183.    ECHO Closing "popup" window.
  184.                   FOR /F "tokens=2 " %%i IN ('PSLIST ^| FIND /I "WINMSG"') DO (KILL -F %%i>NUL && ECHO ... Popup window closed!)
  185.    IF NOT "%OSver%"=="2K"  FOR /F "tokens=2 " %%i IN ('TaskList ^| FIND /I "WINMSG"') DO (KILL -F %%i>NUL && ECHO ... Popup window closed!)
  186. GOTO END
  187. :: #----- END "Post Section"                                           -----#
  188. :: #------------------------------------------------------------------------#
  189.  
  190. :: #------------------------------------------------------------------------#
  191. :: #----- BEGIN "Error messages"                                       -----#
  192. :: #----- END "Erorr Messages"                                         -----#
  193. :: #------------------------------------------------------------------------#
  194. :End
  195. TIMEOUT 15
  196.     :: #- Run throttle system one more time to hopefully force newly restarted Altiris agent to "below normal" status.
  197.    CALL ThrottleCPU.cmd
  198. GOTO :EOF||                            :: Exit batch file and make sure it only runs once.