Récupérer le numéro de version de Forefront

Forefront_Retrieve_Update_Number (WriteActionModuleType)

Récupère le numéro de version de mise à jour d’un moteur à partir du Registre.

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
Comment{683EEAE1-81B4-4B3C-AC32-D1ABB9736CA2}

Member Modules:

ID Module Type TypeId RunAs 
RunScriptAction WriteAction System.Mom.BackwardCompatibility.NoHost.ScriptResponse Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
Enginestring$Config/Parameters/Engine$MoteurSpécifie le nom du moteur ou « null » si le nom du moteur est extrait d'une variable d'état
TextLogstring$Config/Parameters/TextLog$TextLogActive ou désactive la journalisation des fichiers texte dans le script

Source Code:

<WriteActionModuleType ID="Forefront_Retrieve_Update_Number" Comment="{683EEAE1-81B4-4B3C-AC32-D1ABB9736CA2}" Accessibility="Internal" Batching="false">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>MomBackwardCompatibility!System.Mom.BackwardCompatibility.AlertGenerationSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="AlertGeneration" type="AlertGenerationType"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="InvokerType" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Parameters" minOccurs="0">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Engine" type="xsd:string" minOccurs="0"/>
<xsd:element name="TextLog" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="Engine" Selector="$Config/Parameters/Engine$" ParameterType="string"/>
<OverrideableParameter ID="TextLog" Selector="$Config/Parameters/TextLog$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="RunScriptAction" TypeID="MomBackwardCompatibility!System.Mom.BackwardCompatibility.NoHost.ScriptResponse">
<AlertGeneration>$Config/AlertGeneration$</AlertGeneration>
<InvokerType>$Config/InvokerType$</InvokerType>
<Body><Script>

Const FOR_READING = 1

' Constants registry

Const HIVE = "HKEY_LOCAL_MACHINE\"
Const REG_KEY = "SOFTWARE\Microsoft\Forefront Server Security\"
Const REG_KEY_64 = "SOFTWARE\Wow6432Node\Microsoft\Forefront Server Security\"

' Error Constants
INSTALL_PATH_FAIL = 9501
ENG_UPDATE_NUM = 9525

Public ForefrontInstallPath

' Retrieve Script Parameters

EngineParameter = ScriptContext.Parameters.Get("Engine")
TextLogParameter = ScriptContext.Parameters.Get("TextLog")

' Retrieve the local installation path of Forefront

ForefrontInstallPath = RetrieveRegValue (REG_KEY &amp; "Exchange Server","InstalledPath", 1)
if IsNull(ForefrontInstallPath) then
ForefrontInstallPath = RetrieveRegValue (REG_KEY_64 &amp; "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= " &amp; 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= " &amp; EngineName
Else
EngineName = EngineParameter
End If

UpdateRegPath = REG_KEY &amp; InstalledProduct &amp; "\Scan Engines\" &amp; EngineName
UpdateRegPath_64 = REG_KEY_64 &amp; InstalledProduct &amp; "\Scan Engines\" &amp; 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: " &amp; EngineName &amp; " engine was not found on " &amp; ScriptContext.TargetComputer
WriteMOMEvent "WARNING: " &amp; EngineName &amp; " engine was not found on " &amp; ScriptContext.TargetComputer &amp; ". Update number could not be retrieved.", 2, NULL
ScriptContext.Quit
End If

WriteLog EngineName &amp; " Update Version = '" &amp; UpdateNumber &amp; "'"
WriteMOMEvent EngineName &amp; " Update Version = " &amp; UpdateNumber, 4, ENG_UPDATE_NUM

WriteLog "Finished Execution of RetrieveUpdateNumber Script"

'***********************************************************************
'*
'* Function: WriteMOMEvent()
'*
'* Purpose: Writes events to MOM EventLog
'*
'***********************************************************************

Function WriteMOMEvent(EventMessage, EventType, EventNumber)

Dim objEvt
Set objEvt = ScriptContext.CreateEvent

objEvt.Message = EventMessage
objEvt.EventType = EventType

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= " &amp; EngineName

StripEngineName=EngineName


End If


End Function


'********************************************************************
'*
'* Function: RetrieveRegValue
'*
'* Purpose: Retrieves String Value from Registry
'*
'********************************************************************

Function RetrieveRegValue (Key, strValueName, intValueType)

' intValueType -&gt; 1 = String Value
' -&gt; 2 = DWORD Value

const HKEY_LOCAL_MACHINE = &amp;H80000002
Dim strServerName
Dim objReg
Dim strRegValue


On Error Resume Next
Err.Clear
Set objReg=GetObject("winmgmts:\root\default:StdRegProv")
If Err.Number &lt;&gt; 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 &lt;&gt; 0 then
WriteLog "error"
WriteLog strErr.Number
strRegValue = NULL
End If
End If

Set objReg = Nothing

RetrieveRegValue = strRegValue


End Function

'***********************************************************************
'*
'* Function: CreateLogFolder()
'*
'* Purpose: Creates Log subfolder under Forefront
'*
'***********************************************************************

Function CreateLogFolder ()

Dim objFSO
set objFSO = CreateObject ("Scripting.FileSystemObject")

If objFSO.FolderExists(ForefrontInstallPath &amp; "\MOMLogs") = 0 then
objFSO.CreateFolder(ForefrontInstallPath &amp; "\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 &amp; "\MOMLogs\" &amp; "Tasks.log", 8, False)


' If log file doesn't exist - create it
If Err.Number &lt;&gt; 0 Then
Set objf = objfs.CreatetextFile(ForefrontInstallPath &amp; "\MOMLogs\" &amp; "Tasks.log", False)
Err.Clear
End If

If strLogText = "NULL" then
objf.WriteLine("")
Else
strTimeStamp = Date &amp; " " &amp; Time &amp; " "
objf.WriteLine(strTimeStamp &amp; strLogText)
End If

Set objfs = Nothing
Set objf = Nothing
End If

End Function


</Script></Body>
<Language>VBScript</Language>
<Name>Forefront Retrieve Update Number</Name>
<Parameters>
<Parameter>
<Name>Engine</Name>
<Value>$Config/Parameters/Engine$</Value>
</Parameter>
<Parameter>
<Name>TextLog</Name>
<Value>$Config/Parameters/TextLog$</Value>
</Parameter>
</Parameters>
<ManagementPackId>[FSMPack2007_FSE,,1.0.0.1]</ManagementPackId>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="RunScriptAction"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>SystemLibrary!System.BaseData</InputType>
</WriteActionModuleType>