<WriteActionModuleType ID="SMS_2003_Site_Backup_Event_Suppression" Accessibility="Internal" Comment="{D096B7B7-30C9-4B0B-A414-8C170280D145}">
<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"/>
</Configuration>
<ModuleImplementation>
<Composite>
<MemberModules>
<WriteAction ID="RunScriptAction" TypeID="MomBackwardCompatibility!System.Mom.BackwardCompatibility.ScriptResponse">
<AlertGeneration>$Config/AlertGeneration$</AlertGeneration>
<InvokerType>$Config/InvokerType$</InvokerType>
<Body><Script>
'*******************************************************************************
' Script Name - SMS 2003 Site Backup Event Suppression
'
' Purpose - Checks if the SMS Site Backup service is running. If it is not,
' a duplicate event will be created with only its source being
' altered to this script's name.
'
' The following additional events can be raised:
'
' 1100 - An event used only for debugging or tracing.
' 1101 - Script executed successfully.
' 1102 - An error occurred in executing this script.
' 1105 - Accessed denied due to connection failure or permissions.
'
' Assumptions - WMI service must be running in order to determine if the SMS
' Site Backup service is running.
'
' Parameters - None
'
' Change Hist - Date Version Description
' -------- --------------- -----------
' 04/07/04 02.50.0174.0000 Created
'
' (c) Copyright 2004, Microsoft Corp., All Rights Reserved
'*******************************************************************************
'Service the current processing rule. If the event processing rule
'for which this script is executing as a response finds that the SMS
'Site Backup service is running simply return otherwise raise a
'duplicate event with this script's name as its source.
'===================================================================
ServiceCurrentEventProcessingRule
If 0 <> Err.number Then
ScriptError "service current event processing rule." & GetErrorString(Err)
End If
End Sub
'******************************************************************************
' Name: ServiceCurrentEventProcessingRule
'
' Purpose: Service the current processing rule. If the event processing
' rule for which this script is executing as a response finds that
' the SMS Site Backup service is running simply return otherwise
' raise a duplicate event with this script's name as its source.
'
' Parameters: None
'
' Returns: Nothing
'
Sub ServiceCurrentEventProcessingRule()
Dim intServiceStarted
On Error Resume Next
'If the SMS Site Backup service is running, do not create a
'corresponding event processing object. Simply return thereby
'effectively consuming the object.
'=============================================================
'This processing rule has not been placed in maintenance mode. Create
'the appropriate processing object.
'=====================================================================
If ScriptContext.IsEvent() Then
CreateEvent
Else
Err.Raise VB_ERROR_CAN_NOT_PERFORM_OPERATION
Exit Sub
End If
End Sub
'******************************************************************************
' Name: CreateEvent
'
' Purpose: To generate a MOM event for the current event processing rule.
'
' Parameters: None
'
' Returns: Nothing
'
Sub CreateEvent()
'Initialize the properties of the new event object and submit it.
'================================================================
InitializeEvent(objEvent)
If 0 = Err.number Then
ScriptContext.Submit objEvent
End If
Set objEvent = Nothing
End Sub
'******************************************************************************
' Name: InitializeEvent
'
' Purpose: Initialize the specified event to the event in the current script
' context.
'
' Parameters: objEvent, newly created event to be initialized.
'
' Returns: Nothing
'
Sub InitializeEvent(objEvent)
Dim lParamID
Dim lParamCount
Dim strValue
Dim objCurrentEvent
On Error Resume Next
'Initialize the properties of the new event object.
'Note, commented out lines indicate properties that can not be set or
'that are required.
'====================================================================
'Override the event source with this script's name.
'==================================================
objEvent.EventSource = ScriptContext.Name
Set objCurrentEvent = Nothing
End Sub
'******************************************************************************
' Name: IsSMSSiteBackupServiceStarted
'
' Purpose: Checks if the SMS Site Backup service is started, running.
'
' Parameters: None
'
' Returns: Integer, the data to return or zero
'
Function IsSMSSiteBackupServiceStarted()
Dim objServiceSet
Dim objService
Dim strQuery
On Error Resume Next
'Get the status of the SMS Site Backup service. If WMI is not running
'or WMI is inaccessible or backup service is not registered, consider
'the service as not started.
'=====================================================================
strQuery = "select * from Win32_Service where Name='SMS_SITE_BACKUP'"
Set objServiceSet = GetObject("winmgmts:\\"+ ScriptContext.TargetComputer+ "\root\cimv2").ExecQuery(strQuery)
IsSMSSiteBackupServiceStarted = False
If Err Then
Set objServiceSet = Nothing
ScriptError "execute a WMI query to get the WMI Win32_Service object for SMS_SITE_BACKUP." & GetErrorString(Err)
Exit Function
End If
If Not IsEmpty(objServiceSet) Then
For Each objService In objServiceSet
IsSMSSiteBackupServiceStarted = objService.Started
Next
Set objService = Nothing
End If
Set objServiceSet = Nothing
End Function
'******************************************************************************
' Name: GetErrorString
'
' Purpose: Attempts to find the description for an error if an error with no
' description is passed in.
'
' Parameters: oErr, the error object
'
' Returns: String, the description for the error. (Includes the error code.)
'
Function GetErrorString(oErr)
Dim lErr, strErr
lErr = oErr
strErr = oErr.Description
On Error Resume Next
If 0 >= Len(strErr) Then
' If we don't have an error description, then check to see if the error
' is a 0x8007xxxx error. If it is, then look it up.
Const ErrorMask = &HFFFF0000
Const HiWord8007 = &H80070000
Const LoWordMask = 65535 ' This is equivalent to 0x0000FFFF
If (lErr And ErrorMask) = HiWord8007 Then
' Attempt to use 'net helpmsg' to get a description for the error.
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If Err = 0 Then
Dim oExec
Set oExec = oShell.Exec("net helpmsg " & (lErr And LoWordMask))
Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i < 5)
strErr = strMessage
End If
End If
End If
GetErrorString = vbCrLf & "The error returned was: '" & strErr & "' " & lErr & " (0x" & Hex(lErr) & ")"
End Function
'******************************************************************************
' Name: ScriptError
'
' Purpose: To generate a warning about a runtime script error.
'
' Parameters: strError, the description of the error
'
' Returns: Nothing
'
Sub ScriptError(strError)
LogEvent EVENT_ID_SCRIPTERROR, EVENT_TYPE_WARNING, "encountered a runtime error." & vbCrLf & "Failed to " & strError
End Sub
'******************************************************************************
' Name: LogEvent
'
' Purpose: To generate a MOM event
'
' Parameters: lEventID, the event code
' lEventType, the severity of the event
' strMessage, the message to include in the event
'
' Returns: Nothing
'
Sub LogEvent(lEventID, lEventType, strMessage)
Dim objEvent
On Error Resume Next
Set objEvent = ScriptContext.CreateEvent
objEvent.EventNumber = lEventID
objEvent.EventType = lEventType
objEvent.Message = "The script '" & ScriptContext.Name & "' " & strMessage
ScriptContext.Submit objEvent
End Sub </Script></Body>
<Language>VBScript</Language>
<Name>SMS 2003 Site Backup Event Suppression</Name>
<Parameters/>
<ManagementPackId>[Microsoft.SMS.2003,,1.0.0.1]</ManagementPackId>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="RunScriptAction"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>SystemLibrary!System.BaseData</InputType>
</WriteActionModuleType>