Advertisement
Guest User

Untitled

a guest
Jul 12th, 2013
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 4.97 KB | None | 0 0
  1. #cs ----------------------------------------------------------------------------
  2.  
  3.  AutoIt Version: 3.3.6.1
  4.  Author:         Jason S.
  5.  
  6.  Script Function:
  7.     Help automate the process of migrating workstations to new Spark IM program version.
  8.  
  9.     Target Platform(s): Windows 2000, Windows XP, Windows 7
  10.  
  11.     Script will perform the following:
  12.         - Kill current Spark process (if running)
  13.         - Backup chat transcript logs to safe location
  14.         - Initialize the silent uninstaller for current installed Spark program
  15.         - Download and initialize the installation of new Spark program
  16.  
  17. #ce ----------------------------------------------------------------------------
  18.  
  19. ;;;; Start Script ;;;;
  20.  
  21. ; we need permissions to modify programs and write to directories
  22. #RequireAdmin
  23.  
  24. ; Declare includes
  25. #include <Debug.au3>
  26.  
  27. ; Declare constants
  28.  
  29. $SPARK_PROCESS = "Spark.exe"    ; spark process name
  30.  
  31. ; Backup settings
  32. $BACKUP_LOC = "C:\Spark_Backup" ; backup location
  33.  
  34. ; required for network backup instead of local backup
  35. $NET_BACKUP = False           ; set to TRUE to save backup on network instead of local disk
  36. $BACKUP_USER = "someUser"     ; network account with write permissions in $BACKUP_LOC directory
  37. $BACKUP_PASS = "somePassword" ; network account password
  38.  
  39. ; URL to fetch latest spark from - REQUIRES Client Control plugin installed on Openfire Server
  40. $OPENFIRE_SERVER = "http://xmpp.YOURSERVER.net"
  41. $OPENFIRE_ADMIN_PORT = "9090"
  42.  
  43. $SPARK_CLIENTCONTROL = ":" & $OPENFIRE_ADMIN_PORT & "/plugins/clientcontrol/getspark?os=windows"
  44.  
  45. $SPARK_DOWNLOAD = $OPENFIRE_SERVER & $SPARK_CLIENTCONTROL
  46.  
  47. $SETUPTITLE = "Setup - Spark 2.7.1-62713-jsc" ; change me to your version ie: "Setup - Spark 2.6.3"
  48.  
  49. ; Supported OS Versions
  50. ; "WIN_7", "WIN_XP", "WIN_2000"
  51.  
  52. $OS = @OSVersion
  53.  
  54. ; Setup Debug Out
  55. _DebugSetup("Runtime Log");
  56.  
  57. If ($NET_BACKUP) Then
  58.     ; Setup network share credentials
  59.     If (Run("net use " & $BACKUP_LOC & " /user:" & $BACKUP_USER & " " & $BACKUP_PASS) == 0) Then
  60.         _DebugOut("ERROR - Cannot set network share credentials!")
  61.     EndIf
  62. EndIf
  63.  
  64. ; Determine actions
  65. Switch $OS
  66.  
  67.     Case "WIN_XP"
  68.         winXP()
  69.  
  70.     Case "WIN_2000"
  71.         win2000()
  72.  
  73.     Case "WIN_7"
  74.         win7()
  75.  
  76.     Case Else
  77.         _DebugOut("ERROR - Unsupported OS Detected!" & @CRLF & "Detected: " & $OS)
  78.  
  79. EndSwitch
  80.  
  81. ;;;; End Script ;;;;
  82.  
  83. ;; Function to handle Windows XP
  84. Func winXP()
  85.  
  86.     ; Kill Spark running process
  87.     _DebugOut("Killing '" & $SPARK_PROCESS & "' process(s)")
  88.     Kill_Loop()
  89.     ; Backup Spark user account
  90.     _DebugOut("Backup Spark User directory")
  91.     $ok = DirCopy(@AppDataDir & "\Spark\user", $BACKUP_LOC, 0)
  92.     If ($ok <> 1) Then
  93.         _DebugOut("Failed to backup Spark User directory")
  94.     Else
  95.         _DebugOut("Backup Spark User directory Success!")
  96.     EndIf
  97.  
  98.     ; Uninstall Spark
  99.     _DebugOut("Uninstalling existing Spark")
  100.     $ok = Run(@ProgramFilesDir & "\Spark\uninstall.exe -q")
  101.     If ($ok <> 0) Then
  102.         _DebugOut("Spark Uninstalled Successfully")
  103.     Else
  104.         _DebugOut("Uninstall of Spark Failed")
  105.         _DebugOut("Please uninstall manually")
  106.         Run(@ComSpec & " /c " & @SystemDir & "\appwiz.cpl", "", @SW_HIDE)
  107.         WinWait("Add or Remove Programs")
  108.  
  109.         While (WinExists("Add or Remove Programs"))
  110.             Sleep(1000)
  111.         WEnd
  112.     EndIf
  113.  
  114.     ; Kill Spark left-over files
  115.     _DebugOut("Killing old Spark files")
  116.     DirRemove(@AppDataDir & "\Spark", 1)
  117.     _DebugOut("Old Spark is now cleaned up")
  118.  
  119.     ; Download new Spark Version
  120.     _DebugOut("Starting Spark download")
  121.     InetGet($SPARK_DOWNLOAD, @TempDir & "\spark.exe")
  122.     _DebugOut("Spark download complete!")
  123.  
  124.     ; Start Spark installer
  125.     _DebugOut("Starting Spark installation")
  126.     Run(@TempDir & "\spark.exe")
  127.     WinWait($SETUPTITLE)
  128.  
  129.     ; Wait while we click "Next" a few times
  130.     While (WinExists($SETUPTITLE))
  131.         Sleep(1000)
  132.     WEnd
  133.  
  134.     ; Setup Spark to run at computer login
  135.     _DebugOut("Creating shortcut in startup directory")
  136.     FileCreateShortcut(@ProgramFilesDir & "\Spark\Spark.exe", @ProgramsCommonDir & "\Startup\Spark.lnk", @ProgramFilesDir & "\Spark\Spark.exe")
  137.     _DebugOut("Shortcut created!")
  138.  
  139.     Sleep(1000)
  140.     _DebugOut("Migration Complete!")
  141.  
  142. EndFunc
  143.  
  144. ;; Function to handle Windows 2000
  145. Func win2000()
  146.  
  147.     ; for now, just do XP's path since they are the same
  148.     ; modify here if you want to diverge script logic based on OS version
  149.     winXP()
  150.  
  151. EndFunc
  152.  
  153. ;; Function to handle Windows 7
  154. Func win7()
  155.  
  156.     ; for now, just do XP's path since they are the same
  157.     ; modify here if you want to diverge script logic based on OS version
  158.     winXP()
  159.  
  160. EndFunc
  161.  
  162. ;; Loops and kills all processes of the specified name
  163. Func Kill_Loop()
  164.  
  165.     While (ProcessExists($SPARK_PROCESS) <> 0)
  166.  
  167.         _DebugOut("Found '" & $SPARK_PROCESS & "' process running!")
  168.         Kill_Process($SPARK_PROCESS)
  169.         Sleep(500)
  170.  
  171.     WEnd
  172.  
  173.     _DebugOut("Killed '" & $SPARK_PROCESS & "' process!")
  174.  
  175. EndFunc
  176.  
  177. ;; Kills specified process
  178. Func Kill_Process($sPID)
  179.  
  180.     If IsString($sPID) Then $sPID = ProcessExists($sPID)
  181.     If Not $sPID Then Return SetError(1, 0, 0)
  182.  
  183.     Return Run(@ComSpec & " /c taskkill /F /PID " & $sPID & " /T", @SystemDir, @SW_HIDE)
  184.  
  185. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement