' Retrieve the local installation path of Forefront
ForefrontInstallPath = RetrieveRegValue (REG_KEY & "Exchange Server","InstalledPath", 1)
if IsNull(ForefrontInstallPath) then
ForefrontInstallPath = RetrieveRegValue (REG_KEY_64 & "Exchange Server","InstalledPath", 1)
end if
InstalledProduct = "Exchange Server"
'If cannot find Forefront for Exchange, error out.
If IsNull(ForefrontInstallPath) Then
WriteMOMEvent "TASK ERROR: Unable to retrieve Forefront for Exchange installation path", 1
ScriptContext.Quit
End If
' Create Log folder under Forefront installation folder
If TextLogParameter = "true" then
CreateLogFolder()
End If
WriteLog "NULL"
WriteLog "Beginning Execution of RetrieveUpdateNumber Script"
If EngineParameter = "null" or IsNull(EngineParameter) Then
Description = State.get("DescriptionParameter")
WriteLog "Engine Parameter is Null, Get Engine From State DescriptionParameter= " & Description
If Description = "null" or IsNull(Description)or Description="" or Description=" " or IsEmpty(Description) Then
WriteMOMEvent "TASK ERROR: ForefrontRetrieveEngineUpdateNumber ,Engine Param is not specified", 1, INSTALL_PATH_FAIL
ScriptContext.Quit
End If
EngineName = StripEngineName(Description)
WriteLog "Engine Name= " & EngineName
Else
EngineName = EngineParameter
End If
UpdateRegPath = REG_KEY & InstalledProduct & "\Scan Engines\" & EngineName
UpdateRegPath_64 = REG_KEY_64 & InstalledProduct & "\Scan Engines\" & EngineName
WriteLog UpdateRegPath
ScriptContext.Sleep (15000)
UpdateNumber = RetrieveRegValue (UpdateRegPath, "Update Version", 2)
If IsNull(UpdateNumber) or UpdateNumber = "" Then
UpdateNumber = RetrieveRegValue (UpdateRegPath_64, "Update Version", 2)
end if
WriteLog UpdateNumber
'If Update number is null, the engine was not found in the registry
If IsNull(UpdateNumber) or UpdateNumber = "" Then
WriteLog "WARNING: " & EngineName & " engine was not found on " & ScriptContext.TargetComputer
WriteMOMEvent "WARNING: " & EngineName & " engine was not found on " & ScriptContext.TargetComputer & ". Update number could not be retrieved.", 2, NULL
ScriptContext.Quit
End If
WriteLog EngineName & " Update Version = '" & UpdateNumber & "'"
WriteMOMEvent EngineName & " Update Version = " & UpdateNumber, 4, ENG_UPDATE_NUM
WriteLog "Finished Execution of RetrieveUpdateNumber Script"
If Not IsNull(EventNumber) Then
objEvt.EventNumber = EventNumber
End If
ScriptContext.Submit(objEvt)
set objEvt = Nothing
End Function
'********************************************************************
'*
'* Function: StripEngineName
'*
'* Purpose: Strips Engine Name from Event descrition Text
'*
'********************************************************************
Function StripEngineName (EventText)
If not (EventText = "null" or IsNull(EventText) or EventText="" or EventText=" ") Then
EngineName=Trim(EventText)
WriteLog "Final Engine Value= " & EngineName
StripEngineName=EngineName
End If
End Function
'********************************************************************
'*
'* Function: RetrieveRegValue
'*
'* Purpose: Retrieves String Value from Registry
'*
'********************************************************************
Function RetrieveRegValue (Key, strValueName, intValueType)
' intValueType -> 1 = String Value
' -> 2 = DWORD Value
const HKEY_LOCAL_MACHINE = &H80000002
Dim strServerName
Dim objReg
Dim strRegValue
On Error Resume Next
Err.Clear
Set objReg=GetObject("winmgmts:\root\default:StdRegProv")
If Err.Number <> 0 Then
Err.Clear
strRegValue = NULL
Else
Select Case intValueType
Case 1
strErr = objReg.GetStringValue (HKEY_LOCAL_MACHINE, Key, strValueName, strRegValue)
Case 2
strErr = objReg.GetDWORDValue (HKEY_LOCAL_MACHINE, Key, strValueName, strRegValue)
End Select
' if reading the registry fails via wmi return error
If strErr <> 0 then
WriteLog "error"
WriteLog strErr.Number
strRegValue = NULL
End If
End If
Dim objFSO
set objFSO = CreateObject ("Scripting.FileSystemObject")
If objFSO.FolderExists(ForefrontInstallPath & "\MOMLogs") = 0 then
objFSO.CreateFolder(ForefrontInstallPath & "\MOMLogs")
End If
Set objFSO = Nothing
End Function
'***********************************************************************
'*
'* Function: WriteLog()
'*
'* Purpose: Writes script activity and errors to a log file
'*
'***********************************************************************
Function WriteLog (strLogText)
If TextLogParameter = "true" Then
Dim objfs
Dim objf
Dim strTimeStamp
On Error Resume Next
Err.Clear
Set objfs = CreateObject("Scripting.FileSystemObject")
Set objf = objfs.OpentextFile(ForefrontInstallPath & "\MOMLogs\" & "Tasks.log", 8, False)
' If log file doesn't exist - create it
If Err.Number <> 0 Then
Set objf = objfs.CreatetextFile(ForefrontInstallPath & "\MOMLogs\" & "Tasks.log", False)
Err.Clear
End If
If strLogText = "NULL" then
objf.WriteLine("")
Else
strTimeStamp = Date & " " & Time & " "
objf.WriteLine(strTimeStamp & strLogText)
End If