#cs ----------------------------------------------------------------------------------------------------------
AutoIt Version: 3.3.0.0
Author: Brent Schmidt <Brent@kiscc.com>
Company: KIS Computer Center
Client:
Date: 5/22/09
Script Function:
Zenworks Configuration Management Adaptive Agent deployment
To be managed by the ZCMdeployment Wizard utility
-------------------------------------------------------------------------------------------------------------
#ce
Opt('MustDeclareVars', 1)
;Global variable declaration.
Global $promptZFD=0, $enableZFD=0, $enableZAM=0, $enableZPM=0, $silentZFD=0, $rebootZFD=0
Global $installZCM=0, $removeZCM=0, $deployver="", $pathZCM="", $enableRegkey=0, $keyname="", $rebootZCM=0
Global $enableAuth=0, $username="", $domain="", $password=""
Global $enableRep=0, $FileReport=0, $EmailReport=0, $SyslogReport=0, $rfilePath="", $smtpServer="", $smtpTo="", $syslogServer=""
Global $dMode, $rMode, $Results, $uString, $sName, $rVal, $rebootNeeded=0
Global $track=0, $sStartKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
Global $Reported, $IEver, $PromptStart, $p, $errorTXT, $zcmversion
Global $StartMSG, $ZFDrunMSG, $ZCMrunMSG, $RebootMSG
;Zenworks for Desktops options
$promptZFD = 1
$enableZFD = 0
$enableZAM = 0
$enableZPM = 0
$silentZFD = 0
$rebootZFD = 0
;Zenworks Adaptive Agent options
$installZCM = 0
$removeZCM = 1
$deployver = "10.0.1.0"
$pathZCM = ""
$enableRegKey = 0
$keyname = ""
$rebootZCM = 1
;Authentication options
$enableAuth = 0
$username = ""
$domain = ""
$password = ""
;Reporting Options
$enableRep = 1
$FileReport = 0
$SyslogReport = 0
$rfilePath = "C:\Temp"
$syslogServer = ""
;Messages options
$StartMSG = "Click Yes to begin upgrading your computer from ZFD to ZCM"
$ZFDrunMSG = "Now removing Zenworks Agents from your PC. For any questions, please contact the help desk"
$ZCMrunMSG = "Now installing Zenworks Adaptive Agent onto your PC. For any questions, please contact the help desk"
$RebootMSG = "Changes done to your computer require a reboot"
;Deployment script
FileInstall ( "clsyslog.dll", @TempDir & "\clsyslog.dll", 1 ); DLL used for sending Syslog messages
$track = RegRead ( "HKLM\SOFTWARE\Novell\Distro", "Track" )
$zcmversion = RegRead ("HKLM\SOFTWARE\Novell\Zenworks", "Version")
If $track = 2 Then Exit
If $silentZFD = 1 Then
$dMode = "quiet"
Else
$dMode = "passive"
EndIf
$rMode = "norestart"
If $domain = "" Then $domain = @ComputerName
If $enableZAM + $enableZPM + $enableZFD + $removeZCM = 0 Then
$track = 1
EndIf
_MeetsMinimum()
If $track = 0 Then
If $PromptZFD = 1 Then
$PromptStart=MsgBox(36,"Zenworks Adaptive Agent Deployment",$StartMSG,60)
Select
Case $PromptStart = 6 ;Yes
;Continue running the script
Case $PromptStart = 7 ;No
Exit
Case $PromptStart = -1 ;Timeout
;Continue running the script
EndSelect
EndIf
If $silentZFD = 0 Then SplashTextOn ("Message", $ZFDrunMSG, 200, 100, -1, 100, 0, "", 8, 800)
If $enableZAM = 1 Then _RemoveZAM()
If $enableZPM = 1 Then _RemoveZPM()
If $enableZFD = 1 Then _RemoveZfD()
If $removeZCM = 1 Then _RemoveZCM()
If $rebootNeeded = 1 Then _Reboot($rebootZFD)
SplashOff()
ElseIf $track = 1 Then
If $silentZFD = 0 Then SplashTextOn ("Message", $ZCMrunMSG, 200, 100, -1, 100, 0, "", 8, 800)
If $installZCM = 1 Then _InstallZCM()
If $rebootNeeded = 1 Then _Reboot($rebootZCM)
SplashOff()
Endif
#cs
###################################################################################################################
###################################################################################################################
Functions##########################################################################################################
###################################################################################################################
###################################################################################################################
#ce
#cs Script Progess Tracking
No value = nothing has started
1 = Removals Completed
2 = Installs Completed
5 = Error already reported
#ce
Func _TrackProgress($p)
If $p = 1 Then RegWrite ( "HKLM\SOFTWARE\Novell\Distro", "Track", "REG_SZ", "1" )
If $p = 2 Then RegWrite ( "HKLM\SOFTWARE\Novell\Distro", "Track", "REG_SZ", "2" )
If $p = 5 Then RegWrite ( "HKLM\SOFTWARE\Novell\Distro", "Reported", "REG_SZ", "1" )
EndFunc
Func _MeetsMinimum()
If @OSVersion = "WIN_VISTA" Then
;continue
ElseIf @OSVersion = "WIN_XP" Then
If @OSServicePack = "Service Pack 2" Then
;continue
ElseIf @OSServicePack = "Service Pack 3" Then
;continue
Else
If $enableRep = 1 Then _ReportError("SP", @OSVersion & " " & @OSServicePack)
Exit
EndIf
ElseIf @OSVersion = "WIN_2000" Then
If @OSServicePack = "Service Pack 4" Then
;continue
Else
If $enableRep = 1 Then _ReportError("SP", @OSVersion & " " & @OSServicePack)
Exit
EndIf
Else
If $enableRep = 1 Then _ReportError("OS", @OSVersion & " " & @OSServicePack)
EndIf
EndFunc
Func _RemoveZAM()
Local $regkey, $string
Local $x, $y, $z
$regkey = RegRead ( "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TSCensus Client Apps", "UninstallString")
$z = StringInStr ($regkey, "UninstFA.isu", 0,-1)
$y = StringLen ($regkey)
$x = $y - $z
$string = StringTrimRight ($regkey, $x + 2)
$z = StringInStr ($string, "-f", 0)
$string = StringTrimLeft ($string, $z + 2)
If $regkey = "" Then
;Do nothing
Else
_StopService("TSCensus Collection Client")
If $enableAuth = 1 Then
RunAsWait ( $username, $domain, $password, 1, $regkey & " -a")
If @error Then _ReportError("RMA", "ZAM")
RunAsWait ( $username, $domain, $password, 1, @ComSpec & " /c " & "rd /s /q " & $string, @SystemDir, @SW_HIDE)
Else
RunWait ( $regkey & " -a" )
If @error Then _ReportError("RMA", "ZAM")
DirRemove ( $string, 1)
EndIf
_TrackProgress(1)
$rebootNeeded = 1
EndIf
EndFunc
Func _RemoveZPM()
RegRead("HKLM\SOFTWARE\Novell\ZENworks\ZfD\Agent","Display Name")
If @error = 1 Then
;Do nothing
Else
_StopService("ZENworks Patch Management Update")
_RemoveMSIApp("ZENworks Patch Management Agent")
_TrackProgress(1)
$rebootNeeded = 1
EndIf
EndFunc
Func _RemoveZfD()
RegRead("HKLM\SOFTWARE\Novell\ZENworks\ZfD\Agent","Display Name")
If @error = 1 Then
;Do nothing
Else
_StopService("Novell Application Launcher")
_StopService("Novell XTier Agent Services")
_StopService("Novell ZENworks Remote Management Agent")
_StopService("Workstation Manager")
_RemoveMSIApp("Novell ZENworks Management Agent Installation")
_TrackProgress(1)
$rebootNeeded = 1
EndIf
EndFunc
Func _InstallZCM()
Local $runCommand, $z
If $zcmversion = $deployver Then Exit
If $silentZFD = 0 Then TrayTip("", "Downloading ZCM Agent", 5, 1)
FileCopy ( $pathZCM, @TempDir, 1)
Sleep(5000)
$z = StringInStr ($pathZCM, "\", 0, -1 )
$runCommand = StringTrimLeft ($pathZCM, $z)
If $enableRegkey = 1 Then
$runCommand = $runCommand & " -k " & $keyname
EndIf
If $enableAuth = 1 Then
If $silentZFD = 0 Then TrayTip("", "Install ZCM with admin credentials", 5, 1)
RunAsWait ( $username, $domain, $password, 1, @TempDir & "\" & $runCommand & " -x", @TempDir, @SW_HIDE )
If @error Then _ReportError("RMA", "ZCM Install")
Else
If $silentZFD = 0 Then TrayTip("", "Install ZCM with local credentials", 5, 1)
RunWait ( @TempDir & "\" & $runCommand & " -x", @TempDir, @SW_HIDE )
If @error Then _ReportError("RMA", "ZCM Install")
EndIf
Sleep(5000)
ProcessWaitClose ("ZENPreAgent.exe")
Sleep(5000)
_TrackProgress(2)
$rebootNeeded = 1
EndFunc
Func _RemoveZCM()
Local $string
$string = Regread("HKLM\SOFTWARE\Novell\Zenworks", "AgentInstallPath")
If @error = 1 Then
;do nothing
Else
_StopService("Novell Identity Store")
_StopService("Novell ZENworks Agent Service")
_StopService("nzwinvnc")
;Zenworks Adaptive Agent Components
_RemoveMSIApp("ZENworks Windows UI")
_RemoveMSIApp("zencore-agent-langs")
_RemoveMSIApp("usermanagement-langs")
_RemoveMSIApp("actions-langs")
_RemoveMSIApp("inventory-langs")
_RemoveMSIApp("windows-desktop-langs")
_RemoveMSIApp("zennotifyicon-langs")
_RemoveMSIApp("policy-langs")
_RemoveMSIApp("remotemanagement-langs")
_RemoveMSIApp("primary-agent-langs")
_RemoveMSIApp("bundle-langs")
_RemoveMSIApp("content-distribution-point-langs")
_RemoveMSIApp("ZENworks Policy Handlers")
_RemoveMSIApp("ZENworks User Management")
_RemoveMSIApp("ZENworks Content Distribution Point")
_RemoveMSIApp("ZENworks Agent Bundle Management")
_RemoveMSIApp("ZENworks Image-Safe Data Agent")
_RemoveMSIApp("ZENworks Actions")
_RemoveMSIApp("ZENworks Agent Inventory Management")
_RemoveMSIApp("Novell ZENworks Remote Management")
_RemoveMSIApp("ZENworks Remote Management")
_RemoveMSIApp("ZENworks Agent WinProxy Module")
_RemoveMSIApp("ZENworks Agent Policy Management")
_RemoveMSIApp("ZENworks Patch Management Agent")
_RemoveMSIApp("ZENworks Agent Patch Management")
_RemoveMSIApp("Policy Action Handler Resources")
_RemoveMSIApp("ZENworks Action Handlers")
_RemoveMSIApp("ZENworks Extensions Libraries")
_RemoveMSIApp("Novell ZENworks Adaptive Agent Help")
_RemoveMSIApp("ZENworks Information Icon")
_RemoveMSIApp("ZENworks Agent Core Modules")
_RemoveMSIApp("Novell CASA Authentication Token Client")
_RemoveMSIApp("ZENworks Uninstaller")
_RemoveMSIApp("ZENworks Primary Agent")
_RemoveMSIApp("CASA")
If $enableAuth = 1 Then
RunAsWait ( $username, $domain, $password, 1, @ComSpec & " /c " & "rd /s /q " & $string, @SystemDir, @SW_HIDE)
RunAsWait ( $username, $domain, $password, 1, @ComSpec & " /c " & @WindowsDir & "\novell", @SystemDir, @SW_HIDE)
Else
DirRemove ( $string, 1)
DirRemove ( @WindowsDir & "\novell", 1)
EndIf
_TrackProgress(1)
$rebootNeeded = 1
EndIf
EndFunc
Func _RemoveMSIApp($sSearchVal)
Local $appMSG
$appMSG = "Detecting " & $sSearchVal & " Installation location"
$Results = _RegSearch($sStartKey, $sSearchVal)
$uString = _GetAppPath($Results, $appMSG)
If $enableAuth = 1 Then
If $silentZFD = 0 Then TrayTip ("", "Uninstalling " & $sSearchVal & " with Administrator credentials", 5, 3)
RunAsWait ( $username, $domain, $password, 1, @SystemDir & "\" & $uString & " /" & $dMode & " /" & $rMode )
If @error Then _ReportError("RMA", $sSearchVal)
Else
If $silentZFD = 0 Then TrayTip ("", "Uninstalling " & $sSearchVal & " with local credentials", 5, 3)
RunWait ( @SystemDir & "\" & $uString & " /" & $dMode & " /" & $rMode )
If @error Then _ReportError("RMA", $sSearchVal)
EndIf
EndFunc
Func _StopService($sName)
If $silentZFD = 0 Then TrayTip ("", "Stopping Service " & $sName, 5, 3)
If $enableAuth = 1 Then
RunAsWait ( $username, $domain, $password, 1, @ComSpec & " /c " & "net stop " & '"' & $sName & '"', @SystemDir, @SW_HIDE)
If @error Then _ReportError("ADM", $sName)
Else
RunWait ( @ComSpec & " /c " & "net stop " & '"' & $sName & '"', @SystemDir, @SW_HIDE)
If @error Then _ReportError("ADM", $sName)
EndIf
TrayTip("","",0)
EndFunc
Func _ReportError($error, $pString)
Local $Reported
If $silentZFD = 0 Then TrayTip ("", "Error found while processing script", 5, 3)
Sleep(5000)
$Reported = RegRead ( "HKLM\SOFTWARE\Novell\Distro", "Reported" )
If $Reported = 1 Then
Exit
ElseIf $error = "SP" Then
$errorTXT = @ComputerName & " " & @UserName & " - Workstation does not meet minimum support pack level"
If $silentZFD = 0 Then TrayTip("", $errorTXT, 5, 3)
ElseIf $error = "OS" Then
$errorTXT = @ComputerName & " " & @UserName & " - Workstation does not run a supported operating system"
If $silentZFD = 0 Then TrayTip("", $errorTXT, 5, 3)
ElseIf $error = "IE" Then
$errorTXT = @ComputerName & " " & @UserName & " - Workstation does not have Internet Explorer 6 or greater installed"
If $silentZFD = 0 Then TrayTip("", $errorTXT, 5, 3)
ElseIf $error = "ADM" Then
$errorTXT = @ComputerName & " " & @UserName & " - Unable to gain administrative access to the workstation"
If $silentZFD = 0 Then TrayTip("", $errorTXT, 5, 3)
ElseIf $error = "RMA" Then
$errorTXT = @ComputerName & " " & @UserName & " - Unable to remove ZENworks application " & $pString
If $silentZFD = 0 Then TrayTip("", $errorTXT, 5, 3)
EndIf
TrayTip("","",0)
If $FileReport = 1 Then _FileLog($rfilePath, $errorTXT)
If $SyslogReport = 1 Then _Syslog($syslogServer, $errorTXT)
RegWrite ( "HKLM\SOFTWARE\Novell\Distro", "Reported", "REG_SZ", "1" )
Exit
EndFunc
Func _FileLog($rfilePath, $errorTXT)
Local $logfile
If $silentZFD = 0 Then TrayTip("", "Writing log file", 5, 1)
$logfile = FileOpen ( $rfilePath & "\" & @ComputerName & "-" & @IPAddress1 & ".log", 10 )
FileWrite ( $logfile, $errorTXT )
TrayTip("","",0)
EndFunc
Func _Syslog($syslogServer, $errorTXT)
Local $dll
If $silentZFD = 0 Then TrayTip("", "Sending syslog message", 5, 1)
$dll = DllOpen( @TempDir & "\clsyslog.dll" )
DLLCall($dll,"int","SlInitialize")
DLLCall($dll,"int","SlSendMessage", "string", $syslogServer,"int", 01,"int", 6,"string",$errorTXT)
DllClose($dll)
TrayTip("","",0)
EndFunc
Func _Reboot($rVal)
Local $iMsgBoxAnswer
If $rVal = 1 Then
$iMsgBoxAnswer = MsgBox(1,"Reboot Needed", $rebootMSG,30)
Select
Case $iMsgBoxAnswer = 1 ;OK
Shutdown(6)
Case $iMsgBoxAnswer = 2 ;Cancel
Exit
Case $iMsgBoxAnswer = -1 ;Timeout
Shutdown(6)
EndSelect
Else
Shutdown(6)
EndIf
EndFunc
Func _GetAppPath($Results, $appMSG)
Local $regKey
Local $w, $x, $y, $z
If $silentZFD = 0 Then TrayTip("", $appMsg, 5, 1)
$z = StringInStr ($Results, "}\", 0,-1)
$y = StringLen ($Results)
$x = $y - $z
$regKey = StringTrimRight ($Results, $x)
$w = RegRead ( $regKey , "UninstallString")
$uString = StringReplace ( $w, "/I", "/X")
TrayTip("","",0)
Return $uString
EndFunc
#cs *****************************************************
Function _RegSearch($sStartKey, $sSearchVal, $iType = 0x07, $fArray = False)
Where: $sStartKey = Reg path at which to begin search
$sSearchVal = The string to search for
$iType = Matching types to return:
1 = Key names
2 = Value names
4 = Value data
Add bits together for multiple match types, default is 7 (all)
$fArray = Return an array of results vice the string (defualt = False)
Performs a recursive search of the registry starting at $sStartKey, looking for $sSearchVal
Returns a string containing a list of key names and values.
If a key name matches, it is listed as a reg path with trailing backslash:
i.e. HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\
If a value name matches, it is listed as a reg path without trailing backslash:
i.e. HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WallPaperDir
If the data matches, the format is path = data:
i.e. HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WallPaperDir = %SystemRoot%\Web\Wallpaper
If $fArray is True, then return data is an array with [0] = count.
*****************************************************
Change Log:
v1.0.0.0 | 03/17/05 | Original SearchReg() by Holger
v2.0.0.0 | 08/10/06 | Native AutoIt version by PsaltyDS
v2.0.0.1 | 08/16/06 | Fixed bug reported by markloman
v2.0.1.0 | 07/30/08 | Added $iType and $fArray parameters
v2.0.2.0 | 11/12/08 | Fixed bug returning array [0] = 1 vice 0 for none found
#ce *****************************************************
Func _RegSearch($sStartKey, $sSearchVal, $iType = 0x07, $fArray = False)
Local $v, $sVal, $k, $sKey, $sFound = "", $avFound[1] = [0]
Local $readval
; Generate type flags
If Not BitAND($iType, 0x07) Then Return SetError(1, 0, 0); No returns selected
Local $fKeys = BitAND($iType, 0x1), $fValue = BitAND($iType, 0x2), $fData = BitAND($iType, 0x4)
; This checks values and data in the current key
If ($fValue Or $fData) Then
$v = 1
While 1
$sVal = RegEnumVal($sStartKey, $v)
If @error = 0 Then
; Valid value - test its name
If $fValue And StringInStr($sVal, $sSearchVal) Then $sFound &= $sStartKey & "\" & $sVal & @LF
; test its data
If $fData Then
$readval = RegRead($sStartKey, $sVal)
If StringInStr($readval, $sSearchVal) Then
$sFound &= $sStartKey & "\" & $sVal & " = " & $readval & @LF
EndIf
EndIf
$v += 1
Else
; No more values here
ExitLoop
EndIf
WEnd
EndIf
; This loop checks subkeys
$k = 1
While 1
$sKey = RegEnumKey($sStartKey, $k)
If @error = 0 Then
; Valid key - test it's name
If $fKeys And StringInStr($sKey, $sSearchVal) Then $sFound &= $sStartKey & "\" & $sKey & "\" & @LF
; Now search it
$sFound &= _RegSearch($sStartKey & "\" & $sKey, $sSearchVal, $iType)
Else
; No more keys here
ExitLoop
EndIf
$k += 1
WEnd
; Return results
If StringRight($sFound, 1) = @LF Then $sFound = StringTrimRight($sFound, 1)
If $fArray Then
If StringStripWS($sFound, 8) <> "" Then $avFound = StringSplit($sFound, @LF)
Return $avFound
Else
Return $sFound
EndIf
EndFunc ;==>_RegSearch