ConfigMgr 2007 Monitor SMS Status Messages

SMSv4_Monitor_SMS_Status_Messages (WriteActionModuleType)

Monitors specific SMS status messages and raises an event with an event ID corresponding to the SMS status message ID

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
Comment{E4E804C1-0189-47BA-8EB7-91CC4CF8B2C7}

Member Modules:

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

Source Code:

<WriteActionModuleType ID="SMSv4_Monitor_SMS_Status_Messages" Accessibility="Internal" Comment="{E4E804C1-0189-47BA-8EB7-91CC4CF8B2C7}">
<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 - ConfigMgr 2007 Monitor SMS Status Messages
'
' Purpose - Monitor specific SMS status messages and raise an event with an
' event ID that corresponds to the SMS status message ID.
'
' 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 - This script will run on the SMS Site Server and access the SMS
' Site Database on the SQL Server, either locally or remotely.
' Access to the SQL Server will be using Windows Authentication so
' the user context under which the script is run must have access
' to the site database i.e. Local System.
'
' This script does not support agentless mode and will silently
' terminate. This is because of performance reasons and that it
' must proxying on behalf of computers other than the local
' computer it is running on.
'
' The agent will be enabled for proxying for other computers.
'
' Parameters - None
'
' Change Hist - Date Version Description
' -------- --------------- -----------
' 08/27/03 02.50.0102.0000 Added Change History and Patch
' Management messages.
' 09/09/03 02.50.0115.0000 Added Site Backup messages.
' 03/17/04 02.50.0169.0000 Added check for agentless mode.
' 05/17/04 05.0.2700.0000 Added event proxying.
' 09/08/04 05.0.2751.0000 Change to query the SMS Site DB
' directly and not through the SMS WMI
' Provider. Also improved filtering
' on the status message query.
' 10/01/04 05.0.2751.0000 Added status message
' SRVMSG_BACKUP_ERROR_FILESYSTEM_TASK_
' FAILED
' 03/11/05 05.0.2753.0000 Added "Set DATEFORMAT mdy" query
' before querying for SMS status
' messages with a three day filter.
' This resolves previous problem with
' querying on non-english systems.
' 04/23/05 05.0.2754.0000 Updated for ConfigMgr 2007 .
' 05/11/05 05.0.2754.0000 Added status message
' CLIMSG_UPDATESSYNC_ERROR_UPDATE_CATALOG
' 05/13/05 05.0.2754.0000 Removed deprecated status message
' SRVMSG_COLLEVAL_ERROR_SETUP_TABLE
' 01/06/06 05.0.2809.0000 Added status messages
' SRVMSG_SITECOMP_INFO_COMP_INSTALL_
' STARTED
' SRVMSG_SITECOMP_INFO_COMP_INSTALL_
' SUCCEEDED
' 01/11/06 05.0.2810.0000 Updated status message query for
' ConfigMgr 2007 components.
' 03/29/06 05.0.2902.0000 Updated status messages for bugs
' 114299 and 115798.
' 03/31/06 05.0.2902.0000 Added status messages for DCM and OSD.
' 04/13/06 05.0.2902.0000 Added workaround for change from SMS
' SQL Monitor to SMS Database
' Notification Monitor. All discovered
' databases will be assumed active
' until identification information is
' added to the SMS SQL Server.
' 04/21/06 05.0.2902.0000 Added status messages for MP and PXE
' control managers availability check.
' 04/24/06 05.0.2902.0000 Added status messages for SMP Control
' Manager availability check.
' 04/27/06 05.0.2903.0000 Added status messages for MP Control
' Manager DMP availability check.
' 05/01/06 05.0.2904.0000 Changed status message IDs for MP
' Control Manager DMP availability
' check.
' 08/03/06 05.0.2905.0000 Added WOL and SUM status messages.
' 07/30/07 05.0.2906.0000 Added component SMS_MP_DEVICE_MANAGER
' to status message query. Changed
' this script to run on the site server
' as opposed to the SQL Server. Also
' elimited SQL DMO handle leak with
' changes in Sub ProcessStatusMessages().
' Updated status message query with new
' message IDs.
' 08/18/07 6.0.5000.2 Added event tracing support.
' 08/20/07 6.0.5000.3 Added .SCOM2007 before .VarSet in the
' varset file name in order to
' differentiate files from the SCOM
' MOM 2005 management packs.
' 08/22/07 6.0.5000.4 Removed obsolete status message IDs
' 3519, 3520, 3521 and 4403.
' 09/21/07 6.0.5000.6 Changed function
' CheckWow64RegistryKeyExists() to
' not just check for the Wow6432Node
' key but also the SMS key under it.
' 01/11/08 6.0.5000.11 Added code to support site database
' on SQL Server instances.
'
' (c) Copyright 2007, Microsoft Corp., All Rights Reserved
'*******************************************************************************

Option Explicit


'Event Severity Constants
'========================

Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4

Const EVENTLOG_AUDIT_SUCCESS = 8
Const EVENTLOG_AUDIT_FAILURE = 16


'SMS Status Message Severity Constants
'=====================================

Const SMS_STATUS_TYPE_SUCCESS = &amp;H00000000
Const SMS_STATUS_TYPE_ERROR = &amp;HC0000000
Const SMS_STATUS_TYPE_WARNING = &amp;H80000000
Const SMS_STATUS_TYPE_INFORMATION = &amp;H40000000

Const SMS_STATUS_TYPE_MASK = &amp;HC0000000


'Event Number Constants
'======================

Const EVENT_ID_NOTANEVENT = 1100
Const EVENT_ID_SCRIPTSUCCESS = 1101
Const EVENT_ID_SCRIPTERROR = 1102
Const EVENT_ID_ACCESSDENIED = 1105


'SMS Status Message IDs
'======================

Const GENMSG_ERROR_NETWORK_SERVER_IS_DOWN = 505
Const GENMSG_ERROR_SQL_CONNECT = 600
Const GENMSG_ERROR_REGISTRY_READ = 672

Const SRVMSG_SITECOMP_INFO_COMP_INSTALL_STARTED = 1014
Const SRVMSG_SITECOMP_INFO_COMP_INSTALL_SUCCEEDED = 1015
Const SRVMSG_SITECOMP_ERROR_COMP_INSTALL_FAILED = 1016
Const SRVMSG_SITECOMP_ERROR_COMP_REINSTALL_FAILED = 1020
Const SRVMSG_SITECOMP_ERROR_COMP_DEINSTALL_FAILED_AND_ABORTED = 1025
Const SRVMSG_SITECOMP_ERROR_SERVER_INSTALL_FAILED = 1028
Const SRVMSG_SITECOMP_ERROR_SERVER_DEINSTALL_FAILED_AND_ABORTED = 1035
Const SRVMSG_SITECOMP_ERROR_SERVER_IS_DOWN = 1037
Const SRVMSG_SITECOMP_ERROR_SERVER_IN_USE_BY_OTHER_SITE = 1048
Const SRVMSG_SITECOMP_ERROR_SERVER_NO_NTFS_DRIVE = 1049
Const SRVMSG_SITECOMP_ERROR_SERVER_COULD_NOT_READ_CONNECT_ACCOUNT = 1055
Const SRVMSG_SITECOMP_ERROR_SERVER_COULD_NOT_WRITE_CONNECT_ACCOUNT = 1056
Const SRVMSG_SITECOMP_INFO_TRANSACTION_SERVICE_ACCT_CHANGED = 1062
Const SRVMSG_SITECOMP_INFO_TRANSACTION_DEINSTALL_SERVER = 1069
Const SRVMSG_SITECOMP_INFO_COMP_DEINSTALLED_THREAD = 1097
Const SRVMSG_SITECOMP_INFO_COMP_COULD_NOT_START_THREAD = 1098
Const SRVMSG_SMSEXEC_ERROR_AUTOSTART_THREAD_COMP_STOPPED = 1104
Const SRVMSG_DISTMGR_ERROR_PROCESS_PKG = 2302
Const SRVMSG_DISTMGR_ERROR_NO_PKG_SRC = 2305
Const SRVMSG_DISTMGR_ERROR_PKG_SRC_NOT_EXIST = 2306
Const SRVMSG_DISTMGR_ERROR_ACCESS_PKG_SRC = 2307
Const SRVMSG_DISTMGR_ERROR_REMOVE_OLD_COMPRESSED_PKG = 2308
Const SRVMSG_DISTMGR_ERROR_COMPRESS_PKG = 2309
Const SRVMSG_DISTMGR_ERROR_UPDATE_PKG = 2312
Const SRVMSG_DISTMGR_ERROR_REMOVE_PKG_DUE_TO_SHARE_CHANGE = 2313
Const SRVMSG_DISTMGR_ERROR_DELETE_STORED_PKG = 2316
Const SRVMSG_DISTMGR_ERROR_NT_HIDDEN_SHARE = 2318
Const SRVMSG_DISTMGR_ERROR_BAD_COMPRESSED_PKG = 2319
Const SRVMSG_DISTMGR_ERROR_NOT_ENOUGH_DISK_SPACE_TO_DECOMPRESS = 2320
Const SRVMSG_DISTMGR_ERROR_DECOMPRESS_PKG = 2321
Const SRVMSG_DISTMGR_ERROR_INIT_NAL = 2323
Const SRVMSG_DISTMGR_ERROR_FIND_EXPORT = 2324
Const SRVMSG_DISTMGR_ERROR_CREATE_SUB_DIR = 2325
Const SRVMSG_DISTMGR_ERROR_SAVE_PKG_STATUS = 2326
Const SRVMSG_DISTMGR_ERROR_SAVE_PKG_INFO = 2327
Const SRVMSG_DISTMGR_ERROR_COPY_PKG = 2328
Const SRVMSG_DISTMGR_ERROR_REMOVE_PKG_FILES = 2332
Const SRVMSG_DISTMGR_ERROR_CREATE_1X_INST_FOR_PKG = 2336
Const SRVMSG_DISTMGR_ERROR_SENT_PKG_TO_CHILD = 2337
Const SRVMSG_DISTMGR_ERROR_CREATE_1X_INST_FOR_PKG_DEF = 2340
Const SRVMSG_DISTMGR_ERROR_SENT_PKG_DEF_TO_CHILD = 2341
Const SRVMSG_DISTMGR_ERROR_NOT_ENOUGH_DISK_SPACE_TO_COPY = 2343
Const SRVMSG_DISTMGR_ERROR_CREATE_VIRTUAL_DIRECTORY = 2344
Const SRVMSG_DISTMGR_ERROR_REMOVE_VIRTUAL_DIRECTORY = 2345
Const SRVMSG_DISTMGR_ERROR_SMS_HIDDEN_SHARE = 2346
Const SRVMSG_DISTMGR_ERROR_REFRESH_DP = 2348
Const SRVMSG_DISTMGR_ERROR_ENABLE_WEBDAV = 2349
Const SRVMSG_DISTMGR_ERROR_INVALID_PCK = 2352
Const SRVMSG_DISTMGR_ERROR_CONFIGURE_SMS_PORTS = 2353
Const SRVMSG_SMSDBMON_WARNING_TASK_EXEC = 2401
Const SRVMSG_SMSDBMON_TASK_MISSED_WINDOW = 2420
Const SRVMSG_COLLEVAL_ERROR_ENUM_COLL = 2500
Const SRVMSG_COLLEVAL_ERROR_REFRESH_COLL = 2511
Const SRVMSG_DDM_ERROR_GET_DISC_SRC = 2601
Const SRVMSG_DATALDR_ERROR_STOPPING_MIF_PROC = 2701
Const SRVMSG_DATALDR_WARNING_SMSDEF_MOF_CONFLICT = 2724
Const SRVMSG_DATALDR_WARNING_SMSDEF_MOF_CONFLICT_SINGLETHREAD = 2725
Const SRVMSG_SITECTRL_INFO_DELTA_FROM_SDK_CLIENT_IS_OLD = 2809
Const SRVMSG_HMAN_ERROR_CONNECT_TO_SQL = 3303
Const SRVMSG_HMAN_INFO_PROCESSED_DB = 3307
Const SRVMSG_SCHED_ERROR_NO_ADDRESS_DEFINED = 3400
Const SRVMSG_SENDER_ERROR_LAN_CONNECTION = 3500
Const SRVMSG_SENDER_ERROR_RAS_CONNECTION = 3501
Const SRVMSG_SENDER_ERROR_CANNOT_START = 3518
Const SRVMSG_SENDER_ERROR_LAN_CONNECTION2 = 3530
Const SRVMSG_SENDER_WARNING_SENDING_PKG = 3532
Const SRVMSG_DESPOOLER_ERROR_BAD_COMPRESSED_PKG = 4401
Const SRVMSG_DESPOOLER_ERROR_COMPRESS_MERGE_FAILED = 4402
Const SRVMSG_DESPOOLER_ERROR_NO_PUB_KEY_OK = 4404
Const SRVMSG_DESPOOLER_ERROR_NO_PUB_KEY = 4405
Const SRVMSG_DESPOOLER_ERROR_BAD_SIGNATURE = 4406
Const SRVMSG_SITECOMP_ERROR_SERVER_COMPONENTS_DEINSTALL_FAILED_AND_ABORTED = 4903
Const SRVMSG_SITECOMP_INFO_COMP_COULD_NOT_ADD_MACHINEACCOUNT = 4908
Const SRVMSG_SITECOMP_CANNOT_FIND_SMS_AD_CONTAINER = 4909
Const SRVMSG_SITECOMP_CANNOT_UPDATE_AD_OBJECT = 4912
Const SRVMSG_SITECOMP_CANNOT_CREATE_AD_OBJECT = 4913
Const SRVMSG_SITECOMP_CANNOT_DELETE_AD_OBJECT = 4915
Const SRVMSG_SITECOMP_CANNOT_UPDATE_MP_PERMISSIONS = 4916
Const SRVMSG_SITECOMP_SLP_CANNOT_CONNECT_TO_SQL = 4917
Const SRVMSG_SITECOMP_ERROR_COMP_BOOTSTRAP_MP_MSI_ERROR = 4951
Const SRVMSG_SITECOMP_ERROR_COMP_BOOTSTRAP_NO_WSUS = 4968
Const SRVMSG_BACKUP_ERROR_CONTROL_FILE_OPEN = 5000
Const SRVMSG_BACKUP_ERROR_COULD_NOT_STOP_EXECUTABLE = 5002
Const SRVMSG_BACKUP_ERROR_COULD_NOT_START_EXECUTABLE = 5004
Const SRVMSG_BACKUP_ERROR_COULD_NOT_STOP_SERVICE = 5006
Const SRVMSG_BACKUP_ERROR_COULD_NOT_START_SERVICE = 5008
Const SRVMSG_BACKUP_ERROR_NO_BACKUP_DEST_DIR = 5025
Const SRVMSG_BACKUP_ERROR_INVALID_BACKUP_DEST_DIR = 5026
Const SRVMSG_BACKUP_ERROR_SYNTAX_ERRORS = 5027
Const SRVMSG_BACKUP_ERROR_REGISTRY_TASK_FAILED = 5032
Const SRVMSG_BACKUP_ERROR_DBBACKUP_TASK_FAILED = 5033
Const SRVMSG_BACKUP_INFO_COMPLETED_SUCCESSFULLY = 5035
Const SRVMSG_BACKUP_ERROR_FILESYSTEM_TASK_FAILED = 5043
Const SRVMSG_BACKUP_ERROR_VSS_INITIALIZATION_FAILED = 5044
Const SRVMSG_BACKUP_ERROR_SMSWRITER_NOTFOUND = 5045
Const SRVMSG_BACKUP_ERROR_GATHERWRITERMETADATA_FAILED = 5046
Const SRVMSG_BACKUP_ERROR_CREATESNAPSHOT_FAILED = 5047
Const SRVMSG_BACKUP_ERROR_BACKUPCOMPLETE_FAILED = 5048
Const SRVMSG_BACKUP_ERROR_CANNOT_READ_SQLREGISTRY = 5049
Const SRVMSG_BACKUP_ERROR_ENTRIES_MISSING_IN_SQLREGISTRY = 5050
Const SRVMSG_BACKUP_ERROR_SQLBACKUP_ALREADY_RUNNING = 5051
Const SRVMSG_BACKUP_ERROR_SQLBACKUP_FAILED = 5052
Const SRVMSG_BACKUP_ERROR_SQLBACKUP_DIDNOT_START = 5053
Const SRVMSG_BACKUP_WARNING_SQL_BACKUP_PATH_EMPTY = 5058
Const MPMSG_FDM_ERROR_CONNECT_TO_SITE_SERVER = 5400
Const MPMSG_CANNOT_READ_MP_CONFIGURATION = 5410
Const MPMSG_CONNECT_DATABASE_FAILED = 5420
Const MPMSG_WINS_REGISTRATION_FAILED = 5430
Const MPMSG_WINS_UNREGISTRATION_FAILED = 5431
Const MPMSG_WRITE_TO_CCM_SETTINGS_FAILED = 5432
Const MPMSG_UPDATE_MP_SETTINGS_FAILED = 5433
Const MPMSG_START_ALL_MP_MANAGERS_FAILED = 5434
Const MPMSG_HTTP_REQUEST_NONRESPONSIVE = 5436
Const MPMSG_HTTP_REQUEST_NLB_NONRESPONSIVE = 5437
Const MPMSG_HTTP_REQUEST_NONRESPONSIVE_ERROR = 5438
Const MPMSG_HTTP_REQUEST_NLB_NONRESPONSIVE_ERROR = 5439
Const MPMSG_HTTP_REQUEST_DMP_NONRESPONSIVE = 5480
Const MPMSG_HTTP_REQUEST_DMP_NONRESPONSIVE_ERROR = 5481


Const MPMSG_HTTP_REQUEST_NLB_NODE_NONRESPONSIVE = 5482
Const MPMSG_HTTP_REQUEST_NLB_NODE_NONRESPONSIVE_ERROR = 5483
Const MPMSG_NLB_NODE_AVAILABILITY_STATE_ONLINE = 5484
Const MPMSG_NLB_NODE_AVAILABILITY_STATE_DEGRADED = 5485
Const MPMSG_NLB_NODE_AVAILABILITY_STATE_OFFLINE = 5486


Const DMPMSG_ERROR_UNEXPECTED = 5700
Const DMPMSG_WARNING_LOW_MEMORY = 5701
Const DMPMSG_ERROR_BAD_DB_CONNECTION = 5702

Const SRVMSG_CIAMGR_ERROR_PROCESSING_CIA_CHANGES = 5804
Const SRVMSG_CIAMGR_WARNING_PROCESSING_CIA = 5805
Const SRVMSG_CIAMGR_ERROR_PROCESSING_CIA = 5806
Const SRVMSG_CIAMGR_ERROR_CIA_FK = 5807
Const SRVMSG_CIAMGR_ERROR_PROCESS_CIA_REPLFILE = 5808
Const SRVMSG_OBJREPLMGR_ERROR_PROCESSING_OBJECT = 6003
Const SRVMSG_OBJREPLMGR_ERROR_PROCESSING_OBJECT_CHANGES = 6004
Const SRVMSG_OBJREPLMGR_ERROR_PROCESS_OBJECT_REPLFILE = 6005
Const SRVMSG_OBJREPLMGR_WARNING_PROCESSING_OBJECT = 6006
Const SRVMSG_OBJREPLMGR_ERROR_SMS_OBJECT_FK = 6007
Const SRVMSG_STATESYSTEM_ERROR_PROCESSING_FILES = 6101
Const SRVMSG_STATESYSTEM_ERROR_PROCESSING_RECORDS = 6102
Const SRVMSG_STATESYSTEM_ERROR_TASK_FAILED = 6103
Const SRVMSG_STATESYSTEM_ERROR_BAD_FILE = 6104
Const SRVMSG_STATESYSTEM_ERROR_INVALID_RECORDS = 6105
Const SRVMSG_SMP_ERROR_READING_REG = 6200
Const SRVMSG_SMP_ERROR_SMPSTORE_MINIMUM_DISKSPACE_REACHED = 6201
Const SRVMSG_SMP_ERROR_SMPSTORE_MAXIMUM_CLIENTS_REACHED = 6202
Const SRVMSG_SMP_WARNING_SMPSTORE_COLLECT_REQUEST_WHEN_STORE_EXISTS = 6203
Const SRVMSG_SMP_WARNING_SMPSTORE_MINIMUM_DISKSPACE_REACHED = 6204
Const SRVMSG_SMP_REQUEST_NONRESPONSIVE = 6207
Const SRVMSG_SMP_REQUEST_NONRESPONSIVE_ERROR = 6208
Const SRVMSG_NBS_ERROR_READING_REG = 6300
Const SRVMSG_NBS_ERROR_PROVIDER_INITIALIZE = 6301
Const SRVMSG_NBS_ERROR_PROVIDER_SHUTDOWN = 6302
Const SRVMSG_NBS_ERROR_INIT_PERFCOUNTERS = 6303
Const SRVMSG_NBS_ERROR_INIT_WORKER_THREADS = 6304
Const SRVMSG_NBS_ERROR_PROCESS_MESSAGE = 6305
Const SRVMSG_NBS_WARNING_PROVIDER_NOT_ACTIVE = 6306
Const SRVMSG_NBS_ERROR_DATABASE_LOOKUP = 6307
Const SRVMSG_NBS_ERROR_DATABASE_BOOTACTION = 6308
Const SRVMSG_NBS_ERROR_BOOT_IMAGE_NOT_AVAILABLE = 6309
Const SRVMSG_PXE_REQUEST_NONRESPONSIVE_ERROR = 6319
Const SRVMSG_PXE_REQUEST_NONRESPONSIVE = 6320
Const SRVMSG_WOL_ERROR_SENDING_PACKETS = 6507
Const SRVMSG_WOL_ERROR_SENDING_PACKETS_HARDFAILURE = 6508
Const SRVMSG_WCM_ERROR_REMOTE_CONFIG = 6600
Const SRVMSG_WCM_ERROR_GET_CATEGORIES = 6602
Const SRVMSG_WCM_ERROR_SUBSCRIBE = 6603
Const SRVMSG_WCM_ERROR_INVALID_API_INSTALL = 6607
Const SRVMSG_WCM_WARNING_SWITCH_TO_WUMU = 6610
Const SRVMSG_WCM_WARNING_CLIENTPUB_WSUS_NOT_CONFIGURED = 6611
Const SRVMSG_WCM_ERROR_CLIENTPUB_PACKAGE_INFO = 6612
Const SRVMSG_WCM_ERROR_CLIENT_PUBLISH = 6613
Const SRVMSG_WCM_ERROR_CLIENT_UNPUBLISH = 6614
Const SRVMSG_WSM_ERROR = 6700
Const SRVMSG_WSM_ERROR_SYNC_FAILED = 6703
Const SRVMSG_ERROR_SYNC_FAILED = 6711
Const SRVMSG_SMSWRITER_ERROR_CONTROL_FILE_OPEN = 6800
Const SRVMSG_SMSWRITER_ERROR_COULD_NOT_STOP_EXECUTABLE = 6802
Const SRVMSG_SMSWRITER_ERROR_COULD_NOT_START_EXECUTABLE = 6804
Const SRVMSG_SMSWRITER_ERROR_COULD_NOT_STOP_SERVICE = 6806
Const SRVMSG_SMSWRITER_ERROR_COULD_NOT_START_SERVICE = 6808
Const SRVMSG_SMSWRITER_ERROR_COULD_NOT_STOP_SMS_CLIENT_APP = 6811
Const SRVMSG_SMSWRITER_ERROR_COULD_NOT_START_SMS_CLIENT_APP = 6813
Const SRVMSG_SMSWRITER_ERROR_SYNTAX_ERRORS = 6814
Const SRVMSG_SMSWRITER_WARNING_SLEEP_LIMIT = 6817
Const SRVMSG_SMSWRITER_ERROR_FILE_NOT_READABLE = 6819
Const SRVMSG_SMSWRITER_ERROR_REGISTRY_TASK_FAILED = 6820
Const SRVMSG_SMSWRITER_ERROR_CANNOT_CREATE_TEMPFILE = 6821
Const SRVMSG_SMSWRITER_ERROR_INITIALIZATION_FAILED = 6825
Const SRVMSG_SMSWRITER_ERROR_SUBSCRIPTION_FAILED = 6826
Const SRVMSG_SMSWRITER_ERROR_BUILDMETADATA_FAILED = 6827
Const SRVMSG_SMSWRITER_WARNING_ALLCOMPS_NOTINCLUDED = 6828
Const SRVMSG_SMSWRITER_WARNING_ABORTING_BACKUP = 6832
Const SRVMSG_WSUSCTRL_ERROR_PROXY_CONFIG = 7000
Const SRVMSG_WSUSCTRL_ERROR_INVALID_SERVER_INSTALL = 7004

Const CLIMSG_UPDATESSYNC_ERROR_NO_SITECODE = 11450
Const CLIMSG_UPDATESSYNC_ERROR_NO_PACKAGEID = 11451
Const CLIMSG_UPDATESSYNC_ERROR_NO_SITENAME = 11452
Const CLIMSG_UPDATESSYNC_ERROR_NO_TARGET = 11453
Const CLIMSG_UPDATESSYNC_ERROR_NO_WRITE_ACCESS = 11454
Const CLIMSG_UPDATESSYNC_ERROR_NO_READ_ACCESS = 11455
Const CLIMSG_UPDATESSYNC_ERROR_SYNC_FAILED = 11456
Const CLIMSG_UPDATESSYNC_INFO_SYNC_SUCCEEDED = 11457
Const CLIMSG_UPDATESSYNC_ERROR_UPDATE_DP = 11458
Const CLIMSG_UPDATESSYNC_ERROR_UPDATE_CATALOG = 11459
Const CLIMSG_UPDATESSYNC_INFO_ERROR_CONTENT_NOTRUST = 11461
Const CLIMSG_UPDATESSYNC_INFO_ERROR_DUPLICATE_TOOL = 11462


'WBEM Flag Constants
'===================

Const wbemFlagReturnImmediately = &amp;H10
Const wbemFlagForwardOnly = &amp;H20


'Debug level constants
'=====================

Const DBG_TRACE = 1
Const DBG_WARNING = 2
Const DBG_ERROR = 3
Const DBG_NONE = 4


'Error constants
'===============

Const ERR_INVALID_DATA = &amp;H8007000D
Const ERR_INVALID_PARAMETER = &amp;H80070057
Const ERR_CANTREAD = &amp;H800703F4
Const ERR_DATABASE_DOES_NOT_EXIST = &amp;H80070429
Const ERR_BAD_CONFIGURATION = &amp;H8007064A
Const ERR_INVALID_TABLE = &amp;H8007065C
Const ERR_DATABASE_FAILURE = &amp;H800710D9


'Other constants
'===============

Const VAR_LAST_RECORD_ID = "LastRecordID"


' Global variables
'=================

Dim g_oUtil ' Utility class for MOM events, logging and registry access.
Dim g_oDictionary ' Stores varset data. Note, only string data can be stored.



Sub Main()

Dim bEventTracing

Dim strError


On Error Resume Next


LogMessage DBG_TRACE, ScriptContext.Name &amp; " script starting at local time: " &amp; CStr(Time)

'Check if event tracing is configured. If it is, raise a start event.
'=====================================================================

bEventTracing = IsEventTracingEnabled()

If (bEventTracing = True) Then
LogEvent EVENT_ID_NOTANEVENT, EVENT_TYPE_INFORMATION, "started at local time: " &amp; CStr(Time)
End If

'This script does not support agentless monitoring.
'==================================================

If ScriptContext.IsTargetAgentless Then
LogMessage DBG_TRACE, "No action taken; agentless monitoring is not supported."
LogMessage DBG_TRACE, ScriptContext.Name &amp; " script completed at local time: " &amp; CStr(Time)
Exit Sub
End If

'Initialize utility object and set tracing leve for it.
'======================================================

Set g_oUtil = new Util

If IsEmpty(g_oUtil) Then
LogMessage DBG_TRACE, "Failed to instantiate Util object."
ScriptError "instantiate Util object."
LogMessage DBG_TRACE, ScriptContext.Name &amp; " script completed at local time: " &amp; CStr(Time)
Exit Sub
End If

g_oUtil.SetDebugLevel(g_oUtil.DBG_TRACE)

'Initialize the persistent var set this script uses.
'====================================================

OpenVarSet

If 0 &lt;&gt; Err.number Then
strError = GetErrorString(Err)
LogMessage DBG_ERROR, "Failed to load script variables." &amp; strError
ScriptError "load script variables." &amp; strError
Set g_oUtil = Nothing
LogMessage DBG_TRACE, ScriptContext.Name &amp; " script completed at local time: " &amp; CStr(Time)
Exit Sub
End If

'Process status messages found in the SQL SMS Site Databases on
'this machine.
'==============================================================

ProcessStatusMessages

If 0 &lt;&gt; Err.number Then
strError = GetErrorString(Err)
LogMessage DBG_ERROR, "Failed to process status messages in SMS site database." &amp; strError
ScriptError "process status messages in SMS site database." &amp; strError
End If

'Persist the var set this script uses.
'=====================================

SaveVarSet

If 0 &lt;&gt; Err.number Then
strError = GetErrorString(Err)
LogMessage DBG_ERROR, "Failed to save script variables." &amp; strError
ScriptError "save script variables." &amp; strError
End If

Set g_oUtil = Nothing

If (bEventTracing = True) Then
LogEvent EVENT_ID_SCRIPTSUCCESS, EVENT_TYPE_INFORMATION, "completed at local time: " &amp; CStr(Time)
End If

LogMessage DBG_TRACE, ScriptContext.Name &amp; " script completed at local time: " &amp; CStr(Time)

End Sub


'******************************************************************************
' Name: ProcessStatusMessages
'
' Purpose: Process status messages found in the SMS Site Database.
'
' Parameters: None
'
' Returns: Nothing
'
Sub ProcessStatusMessages()

Dim strDBName
Dim strSQLServer
Dim strSQLServerInstance


On Error Resume Next


LogMessage DBG_TRACE, "Processing status messages."

'Get the name of the SQL server, SQL Server Instance and the Site
'Database.
'================================================================

strSQLServer = GetSQLServerName()

If IsEmpty(strSQLServer) Or (strSQLServer = "") Then
LogMessage DBG_ERROR, "Failed to get SQL Server name."
Err.Raise ERR_BAD_CONFIGURATION
Exit Sub
End If

GetSQLServerInstanceNameAndDatabaseName strSQLServerInstance, strDBName

If Err Then
Exit Sub
End If

'Process the status messages in the site database.
'=================================================

ProcessStatusMessagesInSiteDatabase strSQLServer, strSQLServerInstance, strDBName

End Sub


'******************************************************************************
' Name: GetSQLServerName
'
' Purpose: Gets the name of the SQL Server hosting the SMS Site Database.
'
' Parameters: None
'
' Returns: Registry key string value SOFTWARE\Microsoft\SMS\SQL Server\
' Server
'
Function GetSQLServerName()

GetSQLServerName = g_oUtil.ReadRegistryStringValue(g_oUtil.HKEY_LOCAL_MACHINE, g_oUtil.REG_KEY_SMS_SERVER_SQL_SERVER, g_oUtil.REG_VALUE_SMS_SERVER_SERVER)

End Function


'******************************************************************************
' Name: GetSQLServerInstanceNameAndSiteDatabaseName
'
' Purpose: Gets the name of the SQL Server Instance hosting the SMS Site
' Database as well as the name of the database.
'
' Parameters: strSQLServerInstanceName Instance on the SQL Server hosting the
' site database. If empty, the database
' is on the default instance.
' strSiteDatabaseName The name of the site database.
'
' Returns: Nothing
'
Sub GetSQLServerInstanceNameAndDatabaseName(strSQLServerInstanceName, strSiteDatabaseName)

Dim strDBName
Dim strSQLServer
Dim strSiteCode

Dim intBackSlashCharPos


On Error Resume Next


LogMessage DBG_TRACE, "Getting SQL Server Instance Name and Site Database Name."

'Get from the registry the value of Database Name.
'=================================================

strDBName = GetSiteDatabaseName()

If IsEmpty(strDBName) Or (strDBName = "") Then
LogMessage DBG_ERROR, "Failed to get SQL Server instance and site database name."
Err.Raise ERR_BAD_CONFIGURATION
Exit Sub
End If

'Parse the Database Name to get the SQL Server Instance Name and Site
'Database Name. This is done because the Database Name value was
'overloaded with the SQL Server Instance Name.
'====================================================================

intBackSlashCharPos = InStr(1, strDBName, "\")

If IsNull(intBackSlashCharPos) Or (intBackSlashCharPos = 0) Then

If Not IsEmpty(strSQLServerInstanceName) Then
strSQLServerInstanceName.Empty()
End If

strSiteDatabaseName = strDBName
Else
strSQLServerInstanceName = Left(strDBName, intBackSlashCharPos - 1)
strSiteDatabaseName = Right(strDBName, Len(strDBName) - intBackSlashCharPos)
End If

End Sub


'******************************************************************************
' Name: GetSiteDatabaseName
'
' Purpose: Gets the name of the SMS Site Database.
'
' Parameters: None
'
' Returns: Registry key string value SOFTWARE\Microsoft\SMS\SQL Server\
' Database Name
'
Function GetSiteDatabaseName()

GetSiteDatabaseName = g_oUtil.ReadRegistryStringValue(g_oUtil.HKEY_LOCAL_MACHINE, g_oUtil.REG_KEY_SMS_SERVER_SQL_SERVER, g_oUtil.REG_VALUE_SMS_SERVER_DATABASE_NAME)

End Function


'******************************************************************************
' Name: ProcessStatusMessagesInSiteDatabase
'
' Purpose: Process status messages found in the specified SMS Site Database.
'
' Parameters: strComputer Fully qualified computer name for the SQL
' server.
' strSQLServerInstance Instance on the SQL Server hosting the site
' site database. If empty, the database is
' on the default instance.
' strDBName Name of the SMS Site Database to query.
'
' Returns: Nothing
'
Sub ProcessStatusMessagesInSiteDatabase(strComputer, strSQLServerInstance, strDBName)

Dim cnADOConnection
Dim rsStatusMessage

Dim intRecordCount
Dim intLastRecordID

Dim bFilter
Dim bAscendingOrder
Dim bFirstRun

Dim strError
Dim strParam
Dim strQuery
Dim strLastRecordID

Dim bCreateEvents


On Error Resume Next


'Check input parameters.
'=======================

If IsEmpty(strComputer) Or IsEmpty(strDBName) Then
LogMessage DBG_ERROR, "Invalid input parameter."
Err.Raise ERR_INVALID_PARAMETER
Exit Sub
End If

If IsEmpty(strSQLServerInstance) Then
LogMessage DBG_TRACE, "Processing status messages in site database '" &amp; strDBName &amp; _
"' on SQL Server '" &amp; strComputer &amp; "'."
Else
LogMessage DBG_TRACE, "Processing status messages in site database '" &amp; strDBName &amp; _
"' on SQL Server '" &amp; strComputer &amp; _
"', instance '" &amp; strSQLServerInstance &amp; "'."
End If


'Get the RecordID for the last status message read from this database.
'If the RecordID is null, 0, this can be considered the first status
'message processing run. Only get and save the RecordID of the last
'message in the database.
'====================================================================

strLastRecordID = GetLastRecordID(strDBName)

If strLastRecordID = "" Then
strLastRecordID = "0"
bFilter = False
bAscendingOrder = False
bFirstRun = True
Else
intLastRecordID = CLng(strLastRecordID)
bFilter = True
bAscendingOrder = True
bFirstRun = False
LogMessage DBG_TRACE, "The record ID of the previous last status message processed was '" &amp; intLastRecordID &amp; "'."
End If

'Open a connection to the SMS site database in the default SQL
'instance using the OLE DB provider.
'=============================================================

Set cnADOConnection = CreateObject("ADODB.Connection")

cnADOConnection.Provider = "sqloledb"
cnADOConnection.ConnectionTimeout = 900 '15 minutes
cnADOConnection.CommandTimeout = 900 '15 minutes

If IsEmpty(strSQLServerInstance) Then
strParam = "Server=" &amp; strComputer &amp; ";Database=" &amp; strDBName &amp; ";Trusted_Connection=yes"
Else
strParam = "Server=" &amp; strComputer &amp; "\" &amp; strSQLServerInstance &amp; ";Database=" &amp; strDBName &amp; ";Trusted_Connection=yes"
End If

cnADOConnection.Open strParam

If Err Then
strError = GetErrorString(Err)
If IsEmpty(strSQLServerInstance) Then
LogMessage DBG_ERROR, "Failed to connect to the SMS Site Database '" &amp; strDBName &amp; "' on SQL Server '" &amp; strComputer &amp; "'." &amp; strError
ScriptError "connect to the SMS Site Database '" &amp; strDBName &amp; "' on SQL Server '" &amp; strComputer &amp; "'." &amp; strError
Else
LogMessage DBG_ERROR, "Failed to connect to the SMS Site Database '" &amp; strDBName &amp; "' on SQL Server '" &amp; strComputer &amp; "', instance '" &amp; strSQLServerInstance &amp; "'." &amp; strError
ScriptError "connect to the SMS Site Database '" &amp; strDBName &amp; "' on SQL Server '" &amp; strComputer &amp; "', instance '" &amp; strSQLServerInstance &amp; "'." &amp; strError
End If
Set cnADOConnection = Nothing
Exit Sub
End If

'Set date format for the SMS Status Message query which contains a
'date time filter. The MOM Agent runs under the Locale ID 1033,
'English - United States. If the query is being made to a
'non-english SMS Site Database, we need to tell SQL what format the
'date is in.
'==================================================================

strQuery = "set DATEFORMAT mdy"
LogMessage DBG_TRACE, "Set DATEFORMAT query: " &amp; strQuery

LogMessage DBG_TRACE, "Executing query at local time: " &amp; CStr(Time)
Set rsStatusMessage = cnADOConnection.Execute(strQuery)
LogMessage DBG_TRACE, "Query completed at local time: " &amp; CStr(Time)

If Err Then
LogMessage DBG_ERROR, "Failed to execute set DATEFORMAT query."
cnADOConnection.Close
Set cnADOConnection = Nothing
Exit Sub
End If

'Query for new status messages that are being monitored.
'=======================================================

strQuery = GetSMSStatusMessageQuery(strLastRecordID, bFilter, bAscendingOrder)
LogMessage DBG_TRACE, "SMS Status Message query: " &amp; strQuery

LogMessage DBG_TRACE, "Executing query at local time: " &amp; CStr(Time)
Set rsStatusMessage = cnADOConnection.Execute(strQuery)
LogMessage DBG_TRACE, "Query completed at local time: " &amp; CStr(Time)

If Err Then
LogMessage DBG_ERROR, "Failed to execute status message query."
cnADOConnection.Close
Set cnADOConnection = Nothing
Exit Sub
End If

'Create an event for each returned status message.
'=================================================

intRecordCount = 0

Do While (Not rsStatusMessage.EOF)


'If this is the first processing run, get the RecordID of
'the last message and abort.
'========================================================

If bFirstRun Then
intLastRecordID = rsStatusMessage("RecordID").Value
Exit Do
End If

'If an error occurs while attempting to create the event
'for this SMS status message, stop processing. On the
'the next cycle, processing should resume with this same
'message. Note, if one event should fail to be created
'there is a high probability that all subsequent ones
'will also.
'=======================================================

CreateEvent rsStatusMessage

If Err Then
LogMessage DBG_ERROR, "Failed to create a MOM event for an SMS Status Message."
Exit Do
End If

intRecordCount = intRecordCount + 1
intLastRecordID = rsStatusMessage("RecordID").Value

rsStatusMessage.MoveNext

Loop

'Close the connection to the SMS site database.
'==============================================

cnADOConnection.Close

Set cnADOConnection = Nothing
Set rsStatusMessage = Nothing

'Save the RecordID for the last status message read.
'===================================================

SetLastRecordID strDBName, intLastRecordID

If bFirstRun Then
LogMessage DBG_TRACE, "This is the first run against this database."
LogMessage DBG_TRACE, "Monitoring will start on the next run with status message record ID '" &amp; intLastRecordID &amp; "'."
Else
LogMessage DBG_TRACE, "The total number of status messages processed was '" &amp; intRecordCount &amp; "'."
LogMessage DBG_TRACE, "The record ID of the last status message processed was '" &amp; intLastRecordID &amp; "'."
End If

End Sub


'******************************************************************************
' Name: GetSMSStatusMessageQuery
'
' Purpose: Gets query string for monitored SMS Status Messages.
'
' Parameters: strLastRecordID ID of the last record processed. Returned
' query will specify records with a RecordID
' greater than this value.
' bFilter If TRUE, return query for only specific
' ConfigMgr 2007 messages. If FALSE, return query
' for all messages.
' bAscendingOrder If TRUE, return query for ascending order.
' If FALSE, return query for descending order.
'
' Returns: String, a query ordered by RecordID, ascending or descending
'
Function GetSMSStatusMessageQuery(strLastRecordID, bFilter, bAscendingOrder)

Dim strQuery
Dim strDateTimeUTC


'Construct select statement. If filtering, perform a join to filter
'out everything but ConfigMgr 2007 status messages. Only properties that
'will be used are specified. If not filtering, return everything.
'This will return the RecordID of the last status message.
'===================================================================

If bFilter Then

strQuery = "select " &amp; _
"System.Netbios_Name0, " &amp; _
"System.Resource_Domain_OR_Workgr0, " &amp; _
"StatusMessage.Component, " &amp; _
"StatusMessage.MessageID, " &amp; _
"StatusMessage.ModuleName, " &amp; _
"StatusMessage.RecordID, " &amp; _
"StatusMessage.Severity, " &amp; _
"StatusMessage.SiteCode, " &amp; _
"StatusMessage.TopLevelSiteCode, " &amp; _
"StatusMessage.Win32Error " &amp; _
"from vStatusMessages AS StatusMessage " &amp; _
"join System_DISC as System on StatusMessage.MachineName=System.Netbios_Name0 " &amp; _
"join Sites as Site on StatusMessage.SiteCode=Site.SiteCode " &amp; _
"where Site.Version like '4.00.%' and " &amp; _
"RecordID &gt; " &amp; strLastRecordID &amp; ""

Else

strQuery = "select * from vStatusMessages where RecordID &gt; " &amp; strLastRecordID &amp; ""

End If

'Add filter component if needed.
'===============================

If bFilter Then

'SMS Status Message IDs
'======================

strQuery = strQuery &amp; " and StatusMessage.MessageID in " &amp; _
"(" &amp; _
GENMSG_ERROR_NETWORK_SERVER_IS_DOWN &amp; ", " &amp; _
GENMSG_ERROR_SQL_CONNECT &amp; ", " &amp; _
GENMSG_ERROR_REGISTRY_READ &amp; ", " &amp; _
SRVMSG_SITECOMP_INFO_COMP_INSTALL_STARTED &amp; ", " &amp; _
SRVMSG_SITECOMP_INFO_COMP_INSTALL_SUCCEEDED &amp; ", " &amp; _
SRVMSG_SITECOMP_ERROR_COMP_INSTALL_FAILED &amp; ", " &amp; _
SRVMSG_SITECOMP_ERROR_COMP_REINSTALL_FAILED &amp; ", " &amp; _
SRVMSG_SITECOMP_ERROR_COMP_DEINSTALL_FAILED_AND_ABORTED &amp; ", " &amp; _
SRVMSG_SITECOMP_ERROR_SERVER_INSTALL_FAILED &amp; ", " &amp; _
SRVMSG_SITECOMP_ERROR_SERVER_DEINSTALL_FAILED_AND_ABORTED &amp; ", " &amp; _
SRVMSG_SITECOMP_ERROR_SERVER_IS_DOWN &amp; ", " &amp; _
SRVMSG_SITECOMP_ERROR_SERVER_IN_USE_BY_OTHER_SITE &amp; ", " &amp; _
SRVMSG_SITECOMP_ERROR_SERVER_NO_NTFS_DRIVE &amp; ", " &amp; _
SRVMSG_SITECOMP_ERROR_SERVER_COULD_NOT_READ_CONNECT_ACCOUNT &amp; ", " &amp; _
SRVMSG_SITECOMP_ERROR_SERVER_COULD_NOT_WRITE_CONNECT_ACCOUNT &amp; ", " &amp; _
SRVMSG_SITECOMP_INFO_TRANSACTION_SERVICE_ACCT_CHANGED &amp; ", " &amp; _
SRVMSG_SITECOMP_INFO_TRANSACTION_DEINSTALL_SERVER &amp; ", " &amp; _
SRVMSG_SITECOMP_INFO_COMP_DEINSTALLED_THREAD &amp; ", " &amp; _
SRVMSG_SITECOMP_INFO_COMP_COULD_NOT_START_THREAD &amp; ", " &amp; _
SRVMSG_SMSEXEC_ERROR_AUTOSTART_THREAD_COMP_STOPPED &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_PROCESS_PKG &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_NO_PKG_SRC &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_PKG_SRC_NOT_EXIST &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_ACCESS_PKG_SRC &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_REMOVE_OLD_COMPRESSED_PKG &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_COMPRESS_PKG &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_UPDATE_PKG &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_REMOVE_PKG_DUE_TO_SHARE_CHANGE &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_DELETE_STORED_PKG &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_NT_HIDDEN_SHARE &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_BAD_COMPRESSED_PKG &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_NOT_ENOUGH_DISK_SPACE_TO_DECOMPRESS &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_DECOMPRESS_PKG &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_INIT_NAL &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_FIND_EXPORT &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_CREATE_SUB_DIR &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_SAVE_PKG_STATUS &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_SAVE_PKG_INFO &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_COPY_PKG &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_REMOVE_PKG_FILES &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_CREATE_1X_INST_FOR_PKG &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_SENT_PKG_TO_CHILD &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_CREATE_1X_INST_FOR_PKG_DEF &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_SENT_PKG_DEF_TO_CHILD &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_NOT_ENOUGH_DISK_SPACE_TO_COPY &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_CREATE_VIRTUAL_DIRECTORY &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_REMOVE_VIRTUAL_DIRECTORY &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_SMS_HIDDEN_SHARE &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_REFRESH_DP &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_ENABLE_WEBDAV &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_INVALID_PCK &amp; ", " &amp; _
SRVMSG_DISTMGR_ERROR_CONFIGURE_SMS_PORTS &amp; ", " &amp; _
SRVMSG_SMSDBMON_WARNING_TASK_EXEC &amp; ", " &amp; _
SRVMSG_SMSDBMON_TASK_MISSED_WINDOW &amp; ", " &amp; _
SRVMSG_COLLEVAL_ERROR_ENUM_COLL &amp; ", " &amp; _
SRVMSG_COLLEVAL_ERROR_REFRESH_COLL &amp; ", " &amp; _
SRVMSG_DDM_ERROR_GET_DISC_SRC &amp; ", " &amp; _
SRVMSG_DATALDR_ERROR_STOPPING_MIF_PROC &amp; ", " &amp; _
SRVMSG_DATALDR_WARNING_SMSDEF_MOF_CONFLICT &amp; ", " &amp; _
SRVMSG_DATALDR_WARNING_SMSDEF_MOF_CONFLICT_SINGLETHREAD &amp; ", " &amp; _
SRVMSG_SITECTRL_INFO_DELTA_FROM_SDK_CLIENT_IS_OLD &amp; ", " &amp; _
SRVMSG_HMAN_ERROR_CONNECT_TO_SQL &amp; ", " &amp; _
SRVMSG_HMAN_INFO_PROCESSED_DB &amp; ", " &amp; _
SRVMSG_SCHED_ERROR_NO_ADDRESS_DEFINED &amp; ", " &amp; _
SRVMSG_SENDER_ERROR_LAN_CONNECTION &amp; ", " &amp; _
SRVMSG_SENDER_ERROR_RAS_CONNECTION &amp; ", " &amp; _
SRVMSG_SENDER_ERROR_CANNOT_START &amp; ", " &amp; _
SRVMSG_SENDER_ERROR_LAN_CONNECTION2 &amp; ", " &amp; _
SRVMSG_SENDER_WARNING_SENDING_PKG &amp; ", " &amp; _
SRVMSG_DESPOOLER_ERROR_BAD_COMPRESSED_PKG &amp; ", " &amp; _
SRVMSG_DESPOOLER_ERROR_COMPRESS_MERGE_FAILED &amp; ", " &amp; _
SRVMSG_DESPOOLER_ERROR_NO_PUB_KEY_OK &amp; ", " &amp; _
SRVMSG_DESPOOLER_ERROR_NO_PUB_KEY &amp; ", " &amp; _
SRVMSG_DESPOOLER_ERROR_BAD_SIGNATURE &amp; ", " &amp; _
SRVMSG_SITECOMP_ERROR_SERVER_COMPONENTS_DEINSTALL_FAILED_AND_ABORTED &amp; ", " &amp; _
SRVMSG_SITECOMP_INFO_COMP_COULD_NOT_ADD_MACHINEACCOUNT &amp; ", " &amp; _
SRVMSG_SITECOMP_CANNOT_FIND_SMS_AD_CONTAINER &amp; ", " &amp; _
SRVMSG_SITECOMP_CANNOT_UPDATE_AD_OBJECT &amp; ", " &amp; _
SRVMSG_SITECOMP_CANNOT_CREATE_AD_OBJECT &amp; ", " &amp; _
SRVMSG_SITECOMP_CANNOT_DELETE_AD_OBJECT &amp; ", " &amp; _
SRVMSG_SITECOMP_CANNOT_UPDATE_MP_PERMISSIONS &amp; ", " &amp; _
SRVMSG_SITECOMP_SLP_CANNOT_CONNECT_TO_SQL &amp; ", " &amp; _
SRVMSG_SITECOMP_ERROR_COMP_BOOTSTRAP_MP_MSI_ERROR &amp; ", " &amp; _
SRVMSG_SITECOMP_ERROR_COMP_BOOTSTRAP_NO_WSUS &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_CONTROL_FILE_OPEN &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_COULD_NOT_STOP_EXECUTABLE &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_COULD_NOT_START_EXECUTABLE &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_COULD_NOT_STOP_SERVICE &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_COULD_NOT_START_SERVICE &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_NO_BACKUP_DEST_DIR &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_INVALID_BACKUP_DEST_DIR &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_SYNTAX_ERRORS &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_REGISTRY_TASK_FAILED &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_DBBACKUP_TASK_FAILED &amp; ", " &amp; _
SRVMSG_BACKUP_INFO_COMPLETED_SUCCESSFULLY &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_FILESYSTEM_TASK_FAILED &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_VSS_INITIALIZATION_FAILED &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_SMSWRITER_NOTFOUND &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_GATHERWRITERMETADATA_FAILED &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_CREATESNAPSHOT_FAILED &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_BACKUPCOMPLETE_FAILED &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_CANNOT_READ_SQLREGISTRY &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_ENTRIES_MISSING_IN_SQLREGISTRY &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_SQLBACKUP_ALREADY_RUNNING &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_SQLBACKUP_FAILED &amp; ", " &amp; _
SRVMSG_BACKUP_ERROR_SQLBACKUP_DIDNOT_START &amp; ", " &amp; _
SRVMSG_BACKUP_WARNING_SQL_BACKUP_PATH_EMPTY &amp; ", " &amp; _
MPMSG_FDM_ERROR_CONNECT_TO_SITE_SERVER &amp; ", " &amp; _
MPMSG_CANNOT_READ_MP_CONFIGURATION &amp; ", " &amp; _
MPMSG_CONNECT_DATABASE_FAILED &amp; ", " &amp; _
MPMSG_WINS_REGISTRATION_FAILED &amp; ", " &amp; _
MPMSG_WINS_UNREGISTRATION_FAILED &amp; ", " &amp; _
MPMSG_WRITE_TO_CCM_SETTINGS_FAILED &amp; ", " &amp; _
MPMSG_UPDATE_MP_SETTINGS_FAILED &amp; ", " &amp; _
MPMSG_START_ALL_MP_MANAGERS_FAILED &amp; ", " &amp; _
MPMSG_HTTP_REQUEST_NONRESPONSIVE &amp; ", " &amp; _
MPMSG_HTTP_REQUEST_NLB_NONRESPONSIVE &amp; ", " &amp; _
MPMSG_HTTP_REQUEST_NONRESPONSIVE_ERROR &amp; ", " &amp; _
MPMSG_HTTP_REQUEST_NLB_NONRESPONSIVE_ERROR &amp; ", " &amp; _
MPMSG_HTTP_REQUEST_DMP_NONRESPONSIVE &amp; ", " &amp; _
MPMSG_HTTP_REQUEST_DMP_NONRESPONSIVE_ERROR &amp; ", " &amp; _
MPMSG_HTTP_REQUEST_NLB_NODE_NONRESPONSIVE &amp; ", " &amp; _
MPMSG_HTTP_REQUEST_NLB_NODE_NONRESPONSIVE_ERROR &amp; ", " &amp; _
MPMSG_NLB_NODE_AVAILABILITY_STATE_ONLINE &amp; ", " &amp; _
MPMSG_NLB_NODE_AVAILABILITY_STATE_DEGRADED &amp; ", " &amp; _
MPMSG_NLB_NODE_AVAILABILITY_STATE_OFFLINE &amp; ", " &amp; _
DMPMSG_ERROR_UNEXPECTED &amp; ", " &amp; _
DMPMSG_WARNING_LOW_MEMORY &amp; ", " &amp; _
DMPMSG_ERROR_BAD_DB_CONNECTION &amp; ", " &amp; _
SRVMSG_CIAMGR_ERROR_PROCESSING_CIA_CHANGES &amp; ", " &amp; _
SRVMSG_CIAMGR_WARNING_PROCESSING_CIA &amp; ", " &amp; _
SRVMSG_CIAMGR_ERROR_PROCESSING_CIA &amp; ", " &amp; _
SRVMSG_CIAMGR_ERROR_CIA_FK &amp; ", " &amp; _
SRVMSG_CIAMGR_ERROR_PROCESS_CIA_REPLFILE &amp; ", " &amp; _
SRVMSG_OBJREPLMGR_ERROR_PROCESSING_OBJECT &amp; ", " &amp; _
SRVMSG_OBJREPLMGR_ERROR_PROCESSING_OBJECT_CHANGES &amp; ", " &amp; _
SRVMSG_OBJREPLMGR_ERROR_PROCESS_OBJECT_REPLFILE &amp; ", " &amp; _
SRVMSG_OBJREPLMGR_WARNING_PROCESSING_OBJECT &amp; ", " &amp; _
SRVMSG_OBJREPLMGR_ERROR_SMS_OBJECT_FK &amp; ", " &amp; _
SRVMSG_STATESYSTEM_ERROR_PROCESSING_FILES &amp; ", " &amp; _
SRVMSG_STATESYSTEM_ERROR_PROCESSING_RECORDS &amp; ", " &amp; _
SRVMSG_STATESYSTEM_ERROR_TASK_FAILED &amp; ", " &amp; _
SRVMSG_STATESYSTEM_ERROR_BAD_FILE &amp; ", " &amp; _
SRVMSG_STATESYSTEM_ERROR_INVALID_RECORDS &amp; ", " &amp; _
SRVMSG_SMP_ERROR_READING_REG &amp; ", " &amp; _
SRVMSG_SMP_ERROR_SMPSTORE_MINIMUM_DISKSPACE_REACHED &amp; ", " &amp; _
SRVMSG_SMP_ERROR_SMPSTORE_MAXIMUM_CLIENTS_REACHED &amp; ", " &amp; _
SRVMSG_SMP_WARNING_SMPSTORE_COLLECT_REQUEST_WHEN_STORE_EXISTS &amp; ", " &amp; _
SRVMSG_SMP_WARNING_SMPSTORE_MINIMUM_DISKSPACE_REACHED &amp; ", " &amp; _
SRVMSG_SMP_REQUEST_NONRESPONSIVE &amp; ", " &amp; _
SRVMSG_SMP_REQUEST_NONRESPONSIVE_ERROR &amp; ", " &amp; _
SRVMSG_NBS_ERROR_READING_REG &amp; ", " &amp; _
SRVMSG_NBS_ERROR_PROVIDER_INITIALIZE &amp; ", " &amp; _
SRVMSG_NBS_ERROR_PROVIDER_SHUTDOWN &amp; ", " &amp; _
SRVMSG_NBS_ERROR_INIT_PERFCOUNTERS &amp; ", " &amp; _
SRVMSG_NBS_ERROR_INIT_WORKER_THREADS &amp; ", " &amp; _
SRVMSG_NBS_ERROR_PROCESS_MESSAGE &amp; ", " &amp; _
SRVMSG_NBS_WARNING_PROVIDER_NOT_ACTIVE &amp; ", " &amp; _
SRVMSG_NBS_ERROR_DATABASE_LOOKUP &amp; ", " &amp; _
SRVMSG_NBS_ERROR_DATABASE_BOOTACTION &amp; ", " &amp; _
SRVMSG_NBS_ERROR_BOOT_IMAGE_NOT_AVAILABLE &amp; ", " &amp; _
SRVMSG_PXE_REQUEST_NONRESPONSIVE_ERROR &amp; ", " &amp; _
SRVMSG_PXE_REQUEST_NONRESPONSIVE &amp; ", " &amp; _
SRVMSG_WOL_ERROR_SENDING_PACKETS &amp; ", " &amp; _
SRVMSG_WOL_ERROR_SENDING_PACKETS_HARDFAILURE &amp; ", " &amp; _
SRVMSG_WCM_ERROR_REMOTE_CONFIG &amp; ", " &amp; _
SRVMSG_WCM_ERROR_GET_CATEGORIES &amp; ", " &amp; _
SRVMSG_WCM_ERROR_SUBSCRIBE &amp; ", " &amp; _
SRVMSG_WCM_ERROR_INVALID_API_INSTALL &amp; ", " &amp; _
SRVMSG_WCM_WARNING_SWITCH_TO_WUMU &amp; ", " &amp; _
SRVMSG_WCM_WARNING_CLIENTPUB_WSUS_NOT_CONFIGURED &amp; ", " &amp; _
SRVMSG_WCM_ERROR_CLIENTPUB_PACKAGE_INFO &amp; ", " &amp; _
SRVMSG_WCM_ERROR_CLIENT_PUBLISH &amp; ", " &amp; _
SRVMSG_WCM_ERROR_CLIENT_UNPUBLISH &amp; ", " &amp; _
SRVMSG_WSM_ERROR &amp; ", " &amp; _
SRVMSG_WSM_ERROR_SYNC_FAILED &amp; ", " &amp; _
SRVMSG_ERROR_SYNC_FAILED &amp; ", " &amp; _
SRVMSG_SMSWRITER_ERROR_CONTROL_FILE_OPEN &amp; ", " &amp; _
SRVMSG_SMSWRITER_ERROR_COULD_NOT_STOP_EXECUTABLE &amp; ", " &amp; _
SRVMSG_SMSWRITER_ERROR_COULD_NOT_START_EXECUTABLE &amp; ", " &amp; _
SRVMSG_SMSWRITER_ERROR_COULD_NOT_STOP_SERVICE &amp; ", " &amp; _
SRVMSG_SMSWRITER_ERROR_COULD_NOT_START_SERVICE &amp; ", " &amp; _
SRVMSG_SMSWRITER_ERROR_COULD_NOT_STOP_SMS_CLIENT_APP &amp; ", " &amp; _
SRVMSG_SMSWRITER_ERROR_COULD_NOT_START_SMS_CLIENT_APP &amp; ", " &amp; _
SRVMSG_SMSWRITER_ERROR_SYNTAX_ERRORS &amp; ", " &amp; _
SRVMSG_SMSWRITER_WARNING_SLEEP_LIMIT &amp; ", " &amp; _
SRVMSG_SMSWRITER_ERROR_FILE_NOT_READABLE &amp; ", " &amp; _
SRVMSG_SMSWRITER_ERROR_REGISTRY_TASK_FAILED &amp; ", " &amp; _
SRVMSG_SMSWRITER_ERROR_CANNOT_CREATE_TEMPFILE &amp; ", " &amp; _
SRVMSG_SMSWRITER_ERROR_INITIALIZATION_FAILED &amp; ", " &amp; _
SRVMSG_SMSWRITER_ERROR_SUBSCRIPTION_FAILED &amp; ", " &amp; _
SRVMSG_SMSWRITER_ERROR_BUILDMETADATA_FAILED &amp; ", " &amp; _
SRVMSG_SMSWRITER_WARNING_ALLCOMPS_NOTINCLUDED &amp; ", " &amp; _
SRVMSG_SMSWRITER_WARNING_ABORTING_BACKUP &amp; ", " &amp; _
SRVMSG_WSUSCTRL_ERROR_PROXY_CONFIG &amp; ", " &amp; _
SRVMSG_WSUSCTRL_ERROR_INVALID_SERVER_INSTALL &amp; ", " &amp; _
CLIMSG_UPDATESSYNC_ERROR_NO_SITECODE &amp; ", " &amp; _
CLIMSG_UPDATESSYNC_ERROR_NO_PACKAGEID &amp; ", " &amp; _
CLIMSG_UPDATESSYNC_ERROR_NO_SITENAME &amp; ", " &amp; _
CLIMSG_UPDATESSYNC_ERROR_NO_TARGET &amp; ", " &amp; _
CLIMSG_UPDATESSYNC_ERROR_NO_WRITE_ACCESS &amp; ", " &amp; _
CLIMSG_UPDATESSYNC_ERROR_NO_READ_ACCESS &amp; ", " &amp; _
CLIMSG_UPDATESSYNC_ERROR_SYNC_FAILED &amp; ", " &amp; _
CLIMSG_UPDATESSYNC_INFO_SYNC_SUCCEEDED &amp; ", " &amp; _
CLIMSG_UPDATESSYNC_ERROR_UPDATE_DP &amp; ", " &amp; _
CLIMSG_UPDATESSYNC_ERROR_UPDATE_CATALOG &amp; ", " &amp; _
CLIMSG_UPDATESSYNC_INFO_ERROR_CONTENT_NOTRUST &amp; ", " &amp; _
CLIMSG_UPDATESSYNC_INFO_ERROR_DUPLICATE_TOOL &amp; _
")"

'SMS Server and Patch Management Component names
'===============================================

strQuery = strQuery &amp; " and StatusMessage.Component in " &amp; _
"(" &amp; _
"'SMS_AD_SECURITY_GROUP_DISCOVERY_AGENT', " &amp; _
"'SMS_AD_SYSTEM_DISCOVERY_AGENT', " &amp; _
"'SMS_AD_SYSTEM_GROUP_DISCOVERY_AGENT', " &amp; _
"'SMS_AD_USER_DISCOVERY_AGENT', " &amp; _
"'SMS_ASYNC_RAS_SENDER', " &amp; _
"'SMS_BOOTSTRAP', " &amp; _
"'SMS_CI_ASSIGNMENT_MANAGER', " &amp; _
"'SMS_CLIENT_CONFIG_MANAGER', " &amp; _
"'SMS_CLIENT_INSTALL_DATA_MGR', " &amp; _
"'SMS_COLLECTION_EVALUATOR', " &amp; _
"'SMS_COMPONENT_STATUS_SUMMARIZER', " &amp; _
"'SMS_COURIER_SENDER_CONFIRMATION', " &amp; _
"'SMS_DATABASE_NOTIFICATION_MONITOR', " &amp; _
"'SMS_DESPOOLER', " &amp; _
"'SMS_DEVICE_MANAGEMENT_POINT', " &amp; _
"'SMS_DISCOVERY_DATA_MANAGER', " &amp; _
"'SMS_DISTRIBUTION_MANAGER', " &amp; _
"'SMS_EXECUTIVE', " &amp; _
"'SMS_HIERARCHY_MANAGER', " &amp; _
"'SMS_INBOX_MANAGER', " &amp; _
"'SMS_INBOX_MONITOR', " &amp; _
"'SMS_INVENTORY_DATA_LOADER', " &amp; _
"'SMS_INVENTORY_PROCESSOR', " &amp; _
"'SMS_ISDN_RAS_SENDER', " &amp; _
"'SMS_LAN_SENDER', " &amp; _
"'SMS_MP_CONTROL_MANAGER', " &amp; _
"'SMS_MP_DEVICE_MANAGER', " &amp; _
"'SMS_MP_FILE_DISPATCH_MANAGER', " &amp; _
"'SMS_NETWORK_DISCOVERY', " &amp; _
"'SMS_OBJECT_REPLICATION_MANAGER', " &amp; _
"'SMS_OFFER_MANAGER', " &amp; _
"'SMS_OFFER_STATUS_SUMMARIZER', " &amp; _
"'SMS_POLICY_PROVIDER', " &amp; _
"'SMS_PXE_SERVICE_POINT', " &amp; _
"'SMS_REPLICATION_MANAGER', " &amp; _
"'SMS_REPORTING_POINT', " &amp; _
"'SMS_SCHEDULER', " &amp; _
"'SMS_SERVER_LOCATOR_POINT', " &amp; _
"'SMS_SITE_BACKUP', " &amp; _
"'SMS_SITE_COMPONENT_MANAGER', " &amp; _
"'SMS_SITE_CONTROL_MANAGER', " &amp; _
"'SMS_SITE_SYSTEM_STATUS_SUMMARIZER', " &amp; _
"'SMS_SITE_VSS_WRITER', " &amp; _
"'SMS_SNA_RAS_SENDER', " &amp; _
"'SMS_SOFTWARE_INVENTORY_PROCESSOR', " &amp; _
"'SMS_SOFTWARE_METERING_PROCESSOR', " &amp; _
"'SMS_STATE_MIGRATION_POINT', " &amp; _
"'SMS_STATE_SYSTEM', " &amp; _
"'SMS_STATUS_MANAGER', " &amp; _
"'SMS_SYSTEM_HEALTH_VALIDATOR', " &amp; _
"'SMS_WAKEONLAN_COMMUNICATION_MANAGER', " &amp; _
"'SMS_WAKEONLAN_MANAGER', " &amp; _
"'SMS_WINNT_SERVER_DISCOVERY_AGENT', " &amp; _
"'SMS_WSUS_CONFIGURATION_MANAGER', " &amp; _
"'SMS_WSUS_CONTROL_MANAGER', " &amp; _
"'SMS_WSUS_SYNC_MANAGER', " &amp; _
"'SMS_X25_RAS_SENDER', " &amp; _
"'Software Updates Sync Tool'" &amp; _
")"

'Date and time starting point
'============================

strDateTimeUTC = GetDateTimeUTCQueryFilter()

strQuery = strQuery &amp; " and " &amp; _
"StatusMessage.Time &gt; '" &amp; strDateTimeUTC &amp; "'"

End If

'Add order by qualifier.
'=======================

strQuery = strQuery &amp; " order by RecordID"

'Add asending or descending specifier for how the results will be
'ordered.
'================================================================

If bAscendingOrder Then
strQuery = strQuery &amp; " asc"
Else
strQuery = strQuery &amp; " desc"
End If

'Return the fully constructed query statement.
'=============================================

GetSMSStatusMessageQuery = strQuery

End Function


'******************************************************************************
' Name: GetDateTimeUTCQueryFilter
'
' Purpose: Gets the date and time in UTC format that is to be used to filter
' status messages.
'
' Parameters: None
'
' Returns: String, a date and time
'
Function GetDateTimeUTCQueryFilter()

Dim DateTimeUTC

On Error Resume Next


'Return a data and time in UTC format that is 3 days earlier than the
'current time.
'====================================================================

DateTimeUTC = DateAdd("d", -3, GetCurrentDateTimeUTC()) 'In days

GetDateTimeUTCQueryFilter = FormatDateTime(DateTimeUTC, vbGeneralDate)

End Function


'******************************************************************************
' Name: GetCurrentDateTimeUTC
'
' Purpose: Gets the current date and time in UTC format.
'
' Parameters: None
'
' Returns: Date, current date and time
'
Function GetCurrentDateTimeUTC()

Dim oTimeZone
Dim oTimeZoneSet
Dim CurrentDateTimeLocal
Dim intBias


On Error Resume Next


'Get the instances of this computer's time zone under the WMI CIMV2
'namespace. There will be only one for the current system. Convert
'the current local time to UTC time; UTC = local time + bias. The
'bias is obtained from the Win32_TimeZone class.
'===================================================================

Set oTimeZoneSet = GetObject("winmgmts:").InstancesOf("Win32_TimeZone")

If Err Then
Err.Clear
Exit Function
End If

If Not IsEmpty(oTimeZoneSet) Then

For Each oTimeZone In oTimeZoneSet

'Convert the current local time to UTC time.
'
'A negative time zone bias indicates that the local time is
'earlier than GMT time, a UTC time with zero bias or offset.
'A negative time zone bias must therefore be added to the
'local time. Likewise, a positive one subtracted. The
'daylight savings bias can be added directly though. Thus
'
'Bias = -TimeZoneBias + DaylightSavingsBias
'UTC = LocalTime + Bias. Bias is in minutes.
'===========================================================

CurrentDateTimeLocal = Now

intBias = -oTimeZone.Bias

If Not IsEmpty(oTimeZone.DaylightDay) Then
intBias = intBias + oTimeZone.DaylightBias
End If

GetCurrentDateTimeUTC = DateAdd("n", intBias, CurrentDateTimeLocal) 'In minutes

Next

Set oTimeZoneSet = Nothing

End If

Err.Clear

End Function


'******************************************************************************
' Name: CreateEvent
'
' Purpose: To generate a MOM event for the specified SMS status message.
'
' Parameters: rsStatusMessage, ADO RecordSet object for an SMS Status Message.
'
Sub CreateEvent(rsStatusMessage)

Dim oEvent

Dim lEventType


On Error Resume Next


'Create MOM event object.
'========================

Set oEvent = ScriptContext.CreateEvent

'Initialize Event Type according to SMS status message severity.
'===============================================================

Select Case (SMS_STATUS_TYPE_MASK And rsStatusMessage("Severity").Value)

Case SMS_STATUS_TYPE_SUCCESS

lEventType = EVENT_TYPE_SUCCESS

Case SMS_STATUS_TYPE_ERROR

lEventType = EVENT_TYPE_ERROR

Case SMS_STATUS_TYPE_WARNING

lEventType = EVENT_TYPE_WARNING

Case SMS_STATUS_TYPE_INFORMATION

lEventType = EVENT_TYPE_INFORMATION

End Select

oEvent.EventType = lEventType

'Initialize other event properties with SMS status message properties.
'=====================================================================

oEvent.EventNumber = rsStatusMessage("MessageID").Value
oEvent.Category = rsStatusMessage("SiteCode").Value

'oEvent.SourceDomain = "DOMAIN" ' Domain of SourceComputer
'oEvent.SourceComputer = "MachineName" ' Must be a MOM Agent

oEvent.LoggingDomain = rsStatusMessage("Resource_Domain_OR_Workgr0").Value ' Domain of LoggingComputer
oEvent.LoggingComputer = rsStatusMessage("Netbios_Name0").Value ' Doesn't have to be a MOM Agent

oEvent.SetEventParameter(rsStatusMessage("Netbios_Name0").Value) ' Parameter1
oEvent.SetEventParameter(rsStatusMessage("ModuleName").Value) ' Parameter2
oEvent.SetEventParameter(rsStatusMessage("Component").Value) ' Parameter3
oEvent.SetEventParameter(rsStatusMessage("MessageID").Value) ' Parameter4
oEvent.SetEventParameter(rsStatusMessage("Win32Error").Value) ' Parameter5
oEvent.SetEventParameter(rsStatusMessage("TopLevelSiteCode").Value) ' Parameter6
oEvent.SetEventParameter(rsStatusMessage("RecordID").Value) ' Parameter7

oEvent.Message = "A new monitored SMS status message on machine " &amp; rsStatusMessage("Netbios_Name0").Value &amp; _
" from component " &amp; rsStatusMessage("Component").Value &amp; _
" with message ID " &amp; rsStatusMessage("MessageID").Value &amp; _
" was found in the site " &amp; rsStatusMessage("SiteCode").Value &amp; _
" database."

'Submit, raise, this event to MOM.
'=================================

ScriptContext.Submit oEvent

'Cleanup
'=======

Set oEvent = Nothing

End Sub


'******************************************************************************
' 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
Dim strErr


lErr = oErr
strErr = oErr.Description

On Error Resume Next


If 0 &gt;= 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 = &amp;HFFFF0000
Const HiWord8007 = &amp;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 " &amp; (lErr And LoWordMask))

Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i &lt; 5)

strErr = strMessage

End If

End If

End If

GetErrorString = vbCrLf &amp; "The error returned was: '" &amp; strErr &amp; "' " &amp; lErr &amp; " (0x" &amp; Hex(lErr) &amp; ")"

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." &amp; vbCrLf &amp; "Failed to " &amp; 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 oEvent


On Error Resume Next

Set oEvent = ScriptContext.CreateEvent

oEvent.EventNumber = lEventID
oEvent.EventType = lEventType
oEvent.Message = "The script '" &amp; ScriptContext.Name &amp; "' running under processing rule '" &amp; ScriptContext.ProcessingRule.Name &amp; "' " &amp; strMessage

ScriptContext.Submit oEvent

End Sub


'******************************************************************************
' Name: LogMessage
'
' Purpose: To log a message to ScriptContext and MOM's agent response log.
'
' Parameters: lLevel The debug level for this message i.e. trace,
' warning or error
' strMessage The message to write
'
' Returns: Nothing
'
Sub LogMessage(lLevel, strMessage)

If (lLevel &lt; DBG_NONE) Then

If (lLevel = DBG_ERROR) Then
ScriptContext.Echo "[Error]: " + strMessage
ElseIf (lLevel = DBG_WARNING) Then
ScriptContext.Echo "[Warning]: " + strMessage
ElseIf (lLevel = DBG_TRACE) Then
ScriptContext.Echo "[Trace]:" + strMessage
End If

End If

End Sub


'******************************************************************************
' Name: OpenVarSet
'
' Purpose: Opens a varset file and reads the data from it, into g_oDictionary.
' Only one varset can be open at a single time. Opening a second
' varset will remove the first one. If the first one has not
' been saved then the changes will be lost.
'
' Parameters: None
'
' Returns: Nothing
'
Sub OpenVarSet()

Dim oFSO
Dim oTempFolder
Dim oFile


Set g_oDictionary = CreateObject("Scripting.Dictionary")

Set oFSO = CreateObject("Scripting.FileSystemObject")

If 0 &lt;&gt; Err Then
ScriptError "create Scripting.FileSystemObject." &amp; GetErrorString(Err)
Else

Set oTempFolder = oFSO.GetSpecialFolder(2)

If 0 &lt;&gt; Err Then
ScriptError "find the Temp directory." &amp; GetErrorString(Err)
Else

Set oFile = oFSO.OpenTextFile(oTempFolder.Path &amp; "\" &amp; ScriptContext.Name &amp; ".SCOM2007.VarSet", 1, True, -1)

If 0 &lt;&gt; Err Then
ScriptError "open the '" &amp; ScriptContext.Name &amp; ".SCOM2007.VarSet' file in the Temp directory." &amp; GetErrorString(Err)
Else

Do Until oFile.AtEndOfStream

Dim strLine, iBreak

strLine = oFile.ReadLine()
iBreak = Instr(strLine, vbTab)
g_oDictionary.Add Left(strLine, iBreak - 1), Mid(strLine, iBreak + 1)

Loop

oFile.Close

End If

End If

End If

End Sub


'******************************************************************************
' Name: SaveVarSet
'
' Purpose: Persistently stores the varset on disk, uses the temp directory.
'
' Parameters: None
'
' Returns: Nothing
'
Sub SaveVarSet()

Dim oFSO
Dim oTempFolder
Dim oFile


Set oFSO = CreateObject("Scripting.FileSystemObject")

If 0 &lt;&gt; Err Then
ScriptError "create Scripting.FileSystemObject." &amp; GetErrorString(Err)
Else

Set oTempFolder = oFSO.GetSpecialFolder(2)

If 0 &lt;&gt; Err Then
ScriptError "find the Temp directory." &amp; GetErrorString(Err)
Else

Set oFile = oFSO.CreateTextFile(oTempFolder.Path &amp; "\" &amp; ScriptContext.Name &amp; ".SCOM2007.VarSet", True, True)

If 0 &lt;&gt; Err Then
ScriptError "create the '" &amp; ScriptContext.Name &amp; ".SCOM2007.VarSet' file in the Temp directory." &amp; GetErrorString(Err)
Else

Dim aKeys, aItems, lIndex

aKeys = g_oDictionary.Keys
aItems = g_oDictionary.Items

For lIndex = 0 to g_oDictionary.Count - 1
oFile.WriteLine aKeys(lIndex) &amp; vbTab &amp; aItems(lIndex)
Next

oFile.Close

End If

End If

End If

Set g_oDictionary = nothing

End Sub


'******************************************************************************
' Name: GetData
'
' Purpose: Retrieves data out of a varset. Uses the key to determine what
' data to retrieve.
'
' Parameters: strKey, the key of the data to retrieve
'
' Returns: String, the data to return or an empty string
'
Function GetData(strKey)

If g_oDictionary.Exists(strKey) Then
GetData = g_oDictionary.Item(strKey)
Else
GetData = Empty
End If

End Function


'******************************************************************************
' Name: SetData
'
' Purpose: To store data in a varset. If the key exists then the data
' associated with that key is replaced, otherwise the key/data
' combination is added to the varset.
'
' Parameters: strKey, the key of the line to replace
' Data, the data to associate with the key
'
' Returns: Nothing
'
Sub SetData(strKey, Data)

g_oDictionary.Item(strKey) = Data

End Sub


'******************************************************************************
' Name: GetLastRecordID
'
' Purpose: Retrieves previously saved status message RecordID, for the
' the specified site database, out of a varset.
'
' Parameters: strDBName Name of the queried SMS Site Database.
'
' Returns: String, the data to return or zero
'
Function GetLastRecordID(strDBName)

GetLastRecordID = GetData(VAR_LAST_RECORD_ID &amp; "_" &amp; strDBName)

End Function


'******************************************************************************
' Name: SetLastRecordID
'
' Purpose: Saves the specified Record ID, on a per-database basis, in a
' varset. If the key exists, the data associated with that key is
' replaced, otherwise the key/data combination is added to the
' varset.
'
' Parameters: strDBName Name of the queried SMS Site Database.
' intData The Record ID to save.
'
' Returns: Nothing
'
Sub SetLastRecordID(strDBName, intData)

SetData VAR_LAST_RECORD_ID &amp; "_" &amp; strDBName, intData

End Sub


'==========================================================================
' Class: Util
' Description: Wrapper around WMI.
'==========================================================================
Class Util

'---------------
' Constants (Initialized on constructor due to VBS behavior)
'---------------

'Used to indicate to LogMessage when/how to print the message.
Public DBG_NONE
Public DBG_ERROR
Public DBG_WARNING
Public DBG_TRACE

'Internal Debug Level
Private m_nDebugLevel

'Registry hive constants
Public HKEY_CLASSES_ROOT
Public HKEY_CURRENT_USER
Public HKEY_LOCAL_MACHINE
Public HKEY_USERS
Public HKEY_CURRENT_CONFIG
Public HKEY_DYN_CONFIG

'Registry access permissions
Public KEY_QUERY_VALUE
Public KEY_SET_VALUE
Public KEY_CREATE_SUB_KEY
Public KEY_ENUMERATE_SUB_KEYS
Public KEY_NOTIFY
Public KEY_CREATE_LINK
Public DELETE
Public READ_CONTROL
Public WRITE_DAC
Public WRITE_OWNER

'Registry path and key name constants
Public REG_PATH_SERVICES
Public REG_PATH_SERVICES_BASE

Public REG_PATH_SMS
Public REG_PATH_SMS_BASE

Public REG_PATH_SMS_SERVER

Public REG_PATH_SMS_SERVER_OPMGMT_SMS_SERVER_ROLE
Public REG_PATH_SMS_SERVER_OPMGMT_SMS_SERVER_ROLE_BASE

Public REG_PATH_SMS_SERVER_COMPONENTS
Public REG_PATH_SMS_SERVER_COMPONENTS_BASE

Public REG_PATH_SMS_SERVER_SMSEXEC_COMP_BASE

Public REG_PATH_SMS_SERVER_PROVIDERS
Public REG_PATH_SMS_SERVER_PROVIDERS_BASE

Public REG_KEY_SERVICES_CCMEXEC
Public REG_KEY_SERVICES_SMS_EXECUTIVE
Public REG_KEY_SERVICES_SMS_REPORTING_POINT
Public REG_KEY_SERVICES_SMS_SERVER_LOCATOR_POINT

Public REG_KEY_SMS_SERVER_IDENTIFICATION
Public REG_KEY_SMS_SERVER_OPERATIONS_MANAGEMENT
Public REG_KEY_SMS_SERVER_SETUP
Public REG_KEY_SMS_SERVER_SQL_SERVER

Public REG_KEY_SMS_SERVER_OPMGMT_DISTRIBUTION_POINT
Public REG_KEY_SMS_SERVER_OPMGMT_SITE_SERVER
Public REG_KEY_SMS_SERVER_OPMGMT_SQL_SERVER

Public REG_KEY_SMS_SERVER_SMSEXEC_INBOX_MANAGER_ASSISTANT
Public REG_KEY_SMS_SERVER_SMSEXEC_SMS_LAN_SENDER
Public REG_KEY_SMS_SERVER_SMSEXEC_SMS_MP_CONTROL_MANAGER
Public REG_KEY_SMS_SERVER_SMSEXEC_SMS_MP_FILE_DISPATCH_MANAGER

Public REG_KEY_SMS_SERVER_PROVIDERS

'Registry key value name constants
Public REG_VALUE_SERVICES_DISPLAY_NAME

Public REG_VALUE_SMS_SERVER_VERSION
Public REG_VALUE_SMS_SERVER_FULL_VERSION
Public REG_VALUE_SMS_SERVER_SITE_CODE
Public REG_VALUE_SMS_SERVER_PARENT_SITE_CODE
Public REG_VALUE_SMS_SERVER_CENTRAL_SITE
Public REG_VALUE_SMS_SERVER_BINARY_DIRECTORY
Public REG_VALUE_SMS_SERVER_TYPE
Public REG_VALUE_SMS_SERVER_DATABASE_NAME
Public REG_VALUE_SMS_SERVER_SERVER

'---------------
' Methods
'---------------

'=============
' Method: Class_Initialize
' Description: This is the constructor
' Parameters:
'=============
Private Sub Class_Initialize()

'Initialize Debug level constants
DBG_TRACE = 1
DBG_WARNING = 2
DBG_ERROR = 3
DBG_NONE = 4

'by default only errors are logged
m_nDebugLevel = DBG_ERROR

'Registry hive constants
HKEY_CLASSES_ROOT = &amp;H80000000
HKEY_CURRENT_USER = &amp;H80000001
HKEY_LOCAL_MACHINE = &amp;H80000002
HKEY_USERS = &amp;H80000003
HKEY_CURRENT_CONFIG = &amp;H80000005
HKEY_DYN_CONFIG = &amp;H80000006

'Registry access permissions
KEY_QUERY_VALUE = &amp;H1
KEY_SET_VALUE = &amp;H2
KEY_CREATE_SUB_KEY = &amp;H4
KEY_ENUMERATE_SUB_KEYS = &amp;H8
KEY_NOTIFY = &amp;H10
KEY_CREATE_LINK = &amp;H20
DELETE = &amp;H10000
READ_CONTROL = &amp;H20000
WRITE_DAC = &amp;H40000
WRITE_OWNER = &amp;H80000

'Registry path and key name constants
REG_PATH_SERVICES = "SYSTEM\CurrentControlSet\Services"
REG_PATH_SERVICES_BASE = REG_PATH_SERVICES + "\"

If (CheckWow64RegistryKeyExists() = True) Then
REG_PATH_SMS = "SOFTWARE\Wow6432Node\Microsoft\SMS"
Else
REG_PATH_SMS = "SOFTWARE\Microsoft\SMS"
End If

REG_PATH_SMS_BASE = REG_PATH_SMS + "\"

REG_PATH_SMS_SERVER = REG_PATH_SMS

REG_PATH_SMS_SERVER_OPMGMT_SMS_SERVER_ROLE = REG_PATH_SMS_BASE + "Operations Management\SMS Server Role"
REG_PATH_SMS_SERVER_OPMGMT_SMS_SERVER_ROLE_BASE = REG_PATH_SMS_SERVER_OPMGMT_SMS_SERVER_ROLE + "\"

REG_PATH_SMS_SERVER_COMPONENTS = REG_PATH_SMS_BASE + "COMPONENTS"
REG_PATH_SMS_SERVER_COMPONENTS_BASE = REG_PATH_SMS_SERVER_COMPONENTS + "\"

REG_PATH_SMS_SERVER_SMSEXEC_COMP_BASE = REG_PATH_SMS_SERVER_COMPONENTS_BASE + "SMS_EXECUTIVE\Threads\"

REG_PATH_SMS_SERVER_PROVIDERS = REG_PATH_SMS_BASE + "Providers"
REG_PATH_SMS_SERVER_PROVIDERS_BASE = REG_PATH_SMS_SERVER_PROVIDERS + "\"

REG_KEY_SERVICES_CCMEXEC = REG_PATH_SERVICES_BASE + "CcmExec"
REG_KEY_SERVICES_SMS_EXECUTIVE = REG_PATH_SERVICES_BASE + "SMS_EXECUTIVE"
REG_KEY_SERVICES_SMS_REPORTING_POINT = REG_PATH_SERVICES_BASE + "SMS_REPORTING_POINT"
REG_KEY_SERVICES_SMS_SERVER_LOCATOR_POINT = REG_PATH_SERVICES_BASE + "SMS_SERVER_LOCATOR_POINT"

REG_KEY_SMS_SERVER_IDENTIFICATION = REG_PATH_SMS_BASE + "Identification"
REG_KEY_SMS_SERVER_OPERATIONS_MANAGEMENT = REG_PATH_SMS_BASE + "Operations Management"
REG_KEY_SMS_SERVER_SETUP = REG_PATH_SMS_BASE + "Setup"
REG_KEY_SMS_SERVER_SQL_SERVER = REG_PATH_SMS_BASE + "SQL Server"

REG_KEY_SMS_SERVER_OPMGMT_DISTRIBUTION_POINT = REG_PATH_SMS_SERVER_OPMGMT_SMS_SERVER_ROLE_BASE + "SMS Distribution Point"
REG_KEY_SMS_SERVER_OPMGMT_SITE_SERVER = REG_PATH_SMS_SERVER_OPMGMT_SMS_SERVER_ROLE_BASE + "SMS Site Server"
REG_KEY_SMS_SERVER_OPMGMT_SQL_SERVER = REG_PATH_SMS_SERVER_OPMGMT_SMS_SERVER_ROLE_BASE + "SMS SQL Server"

REG_KEY_SMS_SERVER_SMSEXEC_INBOX_MANAGER_ASSISTANT = REG_PATH_SMS_SERVER_SMSEXEC_COMP_BASE + "SMS_INBOX_MANAGER_ASSISTANT"
REG_KEY_SMS_SERVER_SMSEXEC_SMS_LAN_SENDER = REG_PATH_SMS_SERVER_SMSEXEC_COMP_BASE + "SMS_LAN_SENDER"
REG_KEY_SMS_SERVER_SMSEXEC_SMS_MP_CONTROL_MANAGER = REG_PATH_SMS_SERVER_SMSEXEC_COMP_BASE + "SMS_MP_CONTROL_MANAGER"
REG_KEY_SMS_SERVER_SMSEXEC_SMS_MP_FILE_DISPATCH_MANAGER = REG_PATH_SMS_SERVER_SMSEXEC_COMP_BASE + "SMS_MP_FILE_DISPATCH_MANAGER"

REG_KEY_SMS_SERVER_PROVIDERS = REG_PATH_SMS_SERVER_PROVIDERS

'Registry key value name constants
REG_VALUE_SERVICES_DISPLAY_NAME = "DisplayName"

REG_VALUE_SMS_SERVER_VERSION = "Version"
REG_VALUE_SMS_SERVER_FULL_VERSION = "Full Version"
REG_VALUE_SMS_SERVER_SITE_CODE = "Site Code"
REG_VALUE_SMS_SERVER_PARENT_SITE_CODE = "Parent Site Code"
REG_VALUE_SMS_SERVER_CENTRAL_SITE = "Central Site"
REG_VALUE_SMS_SERVER_BINARY_DIRECTORY = "Binary Directory"
REG_VALUE_SMS_SERVER_TYPE = "Type"
REG_VALUE_SMS_SERVER_DATABASE_NAME = "Database Name"
REG_VALUE_SMS_SERVER_SERVER = "Server"

End Sub

'=============
' Method: Class_Terminate
' Description: This is the destructor
' Parameters:
'=============
Private Sub Class_Terminate()
End Sub

'=============
' Method: SetDebugLevel
' Description: To change the debugging output level of information
' generated by this utility.
' Parameters:
' nLevel - Level, either DBG_NONE, DBG_TRACE,
' DBG_WARNING or DBG_ERROR
'=============
Public Sub SetDebugLevel(ByVal nLevel)
m_nDebugLevel = nLevel
End Sub

'=============
' Method: LogMessage
' Description: Log a debug message to ScriptContext
' Parameters:
' nLevel - Debug level for the message that we're logging.
' strMessage - The message to write to the trace.
'=============
Public Sub LogMessage(ByVal nLevel, ByVal strMessage)

If (nLevel &lt;= m_nDebugLevel) Then
If (nLevel = DBG_ERROR) Then
ScriptContext.Echo "[Error]: " + strMessage
ElseIf (nLevel = DBG_WARNING) Then
ScriptContext.Echo "[Warning]: " + strMessage
ElseIf (nLevel = DBG_TRACE) Then
ScriptContext.Echo "[Trace]:" + strMessage
End If
End If

End Sub

'=============
' Method: ReadRegistryStringValue
' Description: Used to read strings from the registry
' Parameters:
' lHive - Registry hive or root i.e. HKEY_LOCAL_MACHINE
' strKeyPath - Key path for the Registry key to read
' (like "SOFTWARE\Microsoft\WindowsNT\CurrentVersion")
' strValueName - Name of the registry value to read (like "SoftwareType")
'
' Returns:
' The value of the registry key specified. "Nothing" if it fails.
' Callee needs to handle null value return.
'=============
Public Function ReadRegistryStringValue(ByVal lHive, ByVal strKeyPath, ByVal strValueName)

Dim oReg
Dim strValueData

'Get registry provider object
Call LogMessage(DBG_TRACE, "Connecting to WMI Registry : " + "winmgmts:\\"+ ScriptContext.TargetComputer+ "\root\default:StdRegProv")
Set oReg = WMIGetObject("winmgmts:\\"+ ScriptContext.TargetComputer+ "\root\default:StdRegProv")

'Read from value from registry
if oReg.GetStringValue(lHive, strKeyPath, strValueName, strValueData) = 0 Then
Call LogMessage(DBG_TRACE, "Value of Registry Key: " + strKeyPath + "\" + strValueName + " = " + strValueData)
ReadRegistryStringValue = strValueData
Else
Call LogMessage(DBG_ERROR, "Reading Registry Key: " + strKeyPath + "\" + strValueName + " Failed!" )
ReadRegistryStringValue = Empty
End If

Set oReg = Nothing

End Function

'=============
' Method: ReadRegistryDWORDValue
' Description: Used to read DWORDs from the registry
' Parameters:
' lHive - Registry hive or root i.e. HKEY_LOCAL_MACHINE
' strKeyPath - Key path for the Registry key to read
' (like "SOFTWARE\Microsoft\WindowsNT\CurrentVersion")
' strValueName - Name of the registry value to read (like "SoftwareType")
'
' Returns:
' The value of the registry key specified. "Nothing" if it fails.
' Callee needs to handle null value return.
'=============
Public Function ReadRegistryDWORDValue(ByVal lHive, ByVal strKeyPath, ByVal strValueName)

Dim oReg
Dim lValueData

'Get registry provider object
Call LogMessage(DBG_TRACE, "Connecting to WMI Registry : " + "winmgmts:\\"+ ScriptContext.TargetComputer+ "\root\default:StdRegProv")
Set oReg = WMIGetObject("winmgmts:\\"+ ScriptContext.TargetComputer+ "\root\default:StdRegProv")

'Read value from registry
if oReg.GetDWORDValue(lHive, strKeyPath, strValueName, lValueData) = 0 Then
Call LogMessage(DBG_TRACE, "Value of Registry Key: " + strKeyPath + "\" + strValueName + " = " &amp; lValueData)
ReadRegistryDWORDValue = lValueData
Else
Call LogMessage(DBG_ERROR, "Reading Registry Key: " + strKeyPath + "\" + strValueName + " Failed!" )
ReadRegistryDWORDValue = Empty
End If

Set oReg = Nothing

End Function

'=============
' Method: EnumRegistryKeys
' Description: Used to enumerate registry keys under a given path
' Parameters:
' lHive - Registry hive or root i.e. HKEY_LOCAL_MACHINE
' strKeyPath - Key path for the Registry key to read
' (like "SOFTWARE\Microsoft\WindowsNT\CurrentVersion")
' Returns:
' The list of registry keys found under the path. "null" if the list is empty
'=============
Public Function EnumRegistryKeys(ByVal lHive, ByVal strKeyPath)

Dim oReg
Dim arrKeys

'Get registry provider object
Call LogMessage(DBG_TRACE, "Connecting to WMI Registry : " + "winmgmts:\\"+ ScriptContext.TargetComputer+ "\root\default:StdRegProv")
Set oReg = WMIGetObject("winmgmts:\\"+ ScriptContext.TargetComputer + "\root\default:StdRegProv")

'Enumerate keys in registry
if oReg.EnumKey(lHive, strKeyPath, arrKeys) = 0 Then
Call LogMessage(DBG_TRACE, "Found [" + arrKeys(0) + "] key in path : " + strKeyPath )
EnumRegistryKeys = arrKeys
Else
Call LogMessage(DBG_ERROR, "Error enumerating Registry Keys under path : " + strKeyPath )
End If

Set oReg = Nothing

End Function

'=============
' Method: CheckRegistryKeyAccess
' Description: Used to check permissions access to a registry key
' Parameters:
' lHive - Registry hive or root i.e. HKEY_LOCAL_MACHINE
' strKeyPath - Key path for the Registry key to check access
' (like "SOFTWARE\Microsoft\WindowsNT\CurrentVersion")
' lAccess - required permissions i.e. KEY_QUERY_VALUE + KEY_SET_VALUE
' Returns:
' True if the specified permissions are present on the registry key else false.
'=============
Public Function CheckRegistryKeyAccess(ByVal lHive, ByVal strKeyPath, ByVal lAccess)

Dim oReg
Dim bGranted

'Get registry provider object
Call LogMessage(DBG_TRACE, "Connecting to WMI Registry : " + "winmgmts:\\"+ ScriptContext.TargetComputer+ "\root\default:StdRegProv")
Set oReg = WMIGetObject("winmgmts:\\"+ ScriptContext.TargetComputer + "\root\default:StdRegProv")

'Check access to the specified registry key
if oReg.CheckAccess(lHive, strKeyPath, lAccess, bGranted) = 0 Then
Call LogMessage(DBG_TRACE, "Required access present on registry key : " + strKeyPath )
CheckRegistryKeyAccess = bGranted
Else
Call LogMessage(DBG_ERROR, "Error checking access on registry keys : " + strKeyPath )
CheckRegistryKeyAccess = False
End If

Set oReg = Nothing

End Function

'=============
' Method: CheckRegistryKeyExists
' Description: Used to check existence of a registry key
' Parameters:
' lHive - Registry hive or root i.e. HKEY_LOCAL_MACHINE
' strKeyPath - Key path for the Registry key to check access
' (like "SOFTWARE\Microsoft\WindowsNT\CurrentVersion")
' Returns:
' True if the registry key exists else false.
'=============
Public Function CheckRegistryKeyExists(ByVal lHive, ByVal strKeyPath)

CheckRegistryKeyExists = CheckRegistryKeyAccess(lHive, strKeyPath, KEY_QUERY_VALUE)

End Function

'=============
' Method: CheckRegistryKeyStringValueExists
' Description: Used to check existence of a registry key string value
' Parameters:
' lHive - Registry hive or root i.e. HKEY_LOCAL_MACHINE
' strKeyPath - Key path for the Registry key to check access
' (like "SOFTWARE\Microsoft\WindowsNT\CurrentVersion")
' Returns:
' True if the string value exists else false.
'=============
Public Function CheckRegistryKeyStringValueExists(ByVal lHive, ByVal strKeyPath, ByVal strValueName)

Dim strValue

strValue = ReadRegistryStringValue(lHive, strKeyPath, strValueName)

If IsEmpty(strValue) Then
CheckRegistryKeyStringValueExists = False
Else
CheckRegistryKeyStringValueExists = True
End If

End Function

'=============
' Method: CheckRegistryKeyDWORDValueExists
' Description: Used to check existence of a registry key DWORD value
' Parameters:
' lHive - Registry hive or root i.e. HKEY_LOCAL_MACHINE
' strKeyPath - Key path for the Registry key to check access
' (like "SOFTWARE\Microsoft\WindowsNT\CurrentVersion")
' Returns:
' True if the DWORD value exists else false.
'=============
Public Function CheckRegistryKeyDWORDValueExists(ByVal lHive, ByVal strKeyPath, ByVal strValueName)

Dim lValue

lValue = ReadRegistryDWORDValue(lHive, strKeyPath, strValueName)

If IsEmpty(lValue) Then
CheckRegistryKeyDWORDValueExists = False
Else
CheckRegistryKeyDWORDValueExists = True
End If

End Function

End Class


'=============
' Function: CheckWow64RegistryKeyExists
' Description: Used to check existence of registry key
'
' HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node
'
' Parameters: None
' Returns: True if the registry key exists else false.
'=============
Public Function CheckWow64RegistryKeyExists()

Dim oReg
Dim bGranted
Dim strKeyPath
Dim HKEY_LOCAL_MACHINE
Dim KEY_QUERY_VALUE

ScriptContext.Echo "Checking for Wow64 registry key."

'Get registry provider object
ScriptContext.Echo "Connecting to WMI Registry : " + "winmgmts:\\"+ ScriptContext.TargetComputer + "\root\default:StdRegProv"
Set oReg = WMIGetObject("winmgmts:\\"+ ScriptContext.TargetComputer + "\root\default:StdRegProv")

'Check access to the specified registry key
HKEY_LOCAL_MACHINE = &amp;H80000002
strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\SMS"
KEY_QUERY_VALUE = &amp;H1

if oReg.CheckAccess(HKEY_LOCAL_MACHINE, strKeyPath, KEY_QUERY_VALUE, bGranted) = 0 Then
ScriptContext.Echo "Wow64 is present on this computer; found registry key : " + strKeyPath
CheckWow64RegistryKeyExists = bGranted
Else
ScriptContext.Echo "Wow64 is not present on this computer; could not access registry key : " + strKeyPath
CheckWow64RegistryKeyExists = False
End If

Set oReg = Nothing

End Function


'=============
' Function: WMIGetObject
' Description: Returns an object of type SWbemObjectSet
' Parameters:
' sNamespace - A WMI Namespace (ex. winmgmts:\\COMPUTERNAME\ROOT\cimv2).
'=============
Function WMIGetObject(sNamespace)
Dim oWMI
Dim nErrNumber, sErrDescription

On Error Resume Next
Set oWMI = GetObject(sNamespace)
nErrNumber = Err.Number
sErrDescription = Err.Description
On Error Goto 0
If IsEmpty(oWMI) Or nErrNumber &lt;&gt; 0 Then
ScriptContext.Echo "Unable to open WMI Namespace " &amp; sNamespace
Err.Raise 9100, GET_WMI_NO_NAMESPACE_SOURCE(sNamespace), GET_WMI_NO_NAMESPACE_DESCRIPTION(nErrNumber, sErrDescription)
End If

Set WMIGetObject = oWMI

Set oWMI = Nothing
End Function


'=============
' Function: WMIGetInstance
' Description: Returns an object of type SWbemObjectSet
' Parameters:
' sNamespace - A WMI Namespace (ex. winmgmts:\\COMPUTERNAME\ROOT\cimv2).
' sInstance - A WMI Namespace Instance (ex. Win32_OperatingSystem)
'=============
Function WMIGetInstance(sNamespace, sInstance)
Dim oWMI, oInstance
Dim nErrNumber, sErrDescription

On Error Resume Next
Set oWMI = GetObject(sNamespace)
nErrNumber = Err.Number
sErrDescription = Err.Description
On Error Goto 0
If IsEmpty(oWMI) Or nErrNumber &lt;&gt; 0 Then
ScriptContext.Echo "Unable to open WMI Namespace " &amp; sNamespace
Err.Raise 9100, GET_WMI_NO_NAMESPACE_SOURCE(sNamespace), GET_WMI_NO_NAMESPACE_DESCRIPTION(nErrNumber, sErrDescription)
End If

On Error Resume Next
Set oInstance = oWMI.InstancesOf(sInstance)
nErrNumber = Err.Number
sErrDescription = Err.Description
On Error Goto 0
If IsEmpty(oInstance) Or nErrNumber &lt;&gt; 0 Then
ScriptContext.Echo "The class name '" &amp; sInstance &amp; "' returned no instances. Error:" &amp; nErrNumber &amp; ", " &amp; sErrDescription &amp; "."
Err.Raise 9100, GET_WMI_NO_INSTANCES_SOURCE(sInstance), GET_WMI_NO_INSTANCES_DESCRIPTION(nErrNumber, sErrDescription)
End If

'Determine if we queried a valid WMI class - Count will return 0 or empty
On Error Resume Next
Dim nInstanceCount
nInstanceCount = oInstance.Count
nErrNumber = Err.Number
sErrDescription = Err.Description
On Error Goto 0
If nErrNumber &lt;&gt; 0 Then
ScriptContext.Echo "The class name '" &amp; sInstance &amp; "' did not return any valid instances. Error:" &amp; nErrNumber &amp; ", " &amp; sErrDescription &amp; "."
Err.Raise 9100, GET_WMI_NO_VALID_INSTANCES_SOURCE(sInstance), GET_WMI_NO_VALID_INSTANCES_DESCRIPTION(nErrNumber, sErrDescription)
End If

Set WMIGetInstance = oInstance

Set oInstance = Nothing
Set oWMI = Nothing
End Function


'=============
' Function: WMIExecQuery
' Description: Returns an object of type SWbemObjectSet
' Parameters:
' sNamespace - A WMI Namespace (ex. winmgmts:\\COMPUTERNAME\ROOT\cimv2).
' sQuery - A SQL Query (ex. SELECT * FROM Win32_OperatingSystem)
'=============
Function WMIExecQuery(sNamespace, sQuery)
Dim oWMI, oQuery
Dim nErrNumber, sErrDescription

On Error Resume Next
Set oWMI = GetObject(sNamespace)
nErrNumber = Err.Number
sErrDescription = Err.Description
On Error Goto 0

If IsEmpty(oWMI) Or nErrNumber &lt;&gt; 0 Then
ScriptContext.Echo "Unable to open WMI Namespace " &amp; sNamespace
Err.Raise 9100, GET_WMI_NO_NAMESPACE_SOURCE(sNamespace), GET_WMI_NO_NAMESPACE_DESCRIPTION(nErrNumber, sErrDescription)
End If

On Error Resume Next
Set oQuery = oWMI.ExecQuery(sQuery)
nErrNumber = Err.Number
sErrDescription = Err.Description
On Error Goto 0
If IsEmpty(oQuery) Or nErrNumber &lt;&gt; 0 Then
ScriptContext.Echo "The Query '" &amp; sQuery &amp; "' returned an invalid result set. Error:" &amp; nErrNumber &amp; ", " &amp; sErrDescription &amp; "."
Err.Raise 9100, GET_WMI_QUERY_NO_RESULTS_SOURCE(sQuery), GET_WMI_QUERY_NO_RESULTS_DESCRIPTION(nErrNumber, sErrDescription)
End If

'Determine if we queried a valid WMI class - Count will return 0 or empty
On Error Resume Next
Dim nInstanceCount
nInstanceCount = oQuery.Count
nErrNumber = Err.Number
sErrDescription = Err.Description
On Error Goto 0
If nErrNumber &lt;&gt; 0 Then
ScriptContext.Echo "The Query '" &amp; sQuery &amp; "' did not return any valid instances. Error:" &amp; nErrNumber &amp; ", " &amp; sErrDescription &amp; "."
Err.Raise 9100, GET_WMI_QUERY_NO_VALID_INSTANCES_SOURCE(sQuery), GET_WMI_QUERY_NO_VALID_INSTANCES_DESCRIPTION(nErrNumber, sErrDescription)
End If

Set WMIExecQuery = oQuery

Set oQuery = Nothing
Set oWMI = Nothing

End Function


'******************************************************************************
' Name: IsEventTracingEnabled
'
' Purpose: Returns the state of the EventTracingEnabled registry setting.
' This setting is directs scripts raise additional tracing MOM
' events i.e. start and completion events.
'
' Checks for the EventTracingEnabled registry value under the
' following registry paths. If the DWORD values exists, it is read.
'
' HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft Operations Manager
' HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft Operations Manager
'
' Parameters: None
'
' Returns: True if the value exists and is set to 1 else False.
'
Function IsEventTracingEnabled()

Dim strError
Dim lEventTracingEnabled

Dim objShell


On Error Resume Next


LogMessage DBG_TRACE, "Checking EventTracingEnabled registry value."

'Create the WSH Shell object for accessing the registry.
'=======================================================

Set objShell = CreateObject("WScript.Shell")

If Err.number &lt;&gt; 0 Then
IsEventTracingEnabled = False
Exit Function
End If

'Read the EventTracingEnabled value from under the MOM key.
'==========================================================

lEventTracingEnabled = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft Operations Manager\EventTracingEnabled")

If IsEmpty(lEventTracingEnabled) Then

lEventTracingEnabled = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft Operations Manager\EventTracingEnabled")

End If

'Return the appropriate value.
'=============================

If IsEmpty(lEventTracingEnabled) Then

strError = GetErrorString(Err)
LogMessage DBG_TRACE, "Failed to read EventTracingEnabled registry value." &amp; strError

IsEventTracingEnabled = False

Else

LogMessage DBG_TRACE, "EventTracingEnabled registry value is '" &amp; lEventTracingEnabled &amp; "'."

If (lEventTracingEnabled = 1) Then
IsEventTracingEnabled = True
Else
IsEventTracingEnabled = False
End If

End If

Set objShell = Nothing

Err.Clear

End Function</Script></Body>
<Language>VBScript</Language>
<Name>ConfigMgr 2007 Monitor SMS Status Messages</Name>
<Parameters/>
<ManagementPackId>[Microsoft.SystemCenter.ConfigurationManager.2007,,1.0.0.1]</ManagementPackId>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="RunScriptAction"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>SystemLibrary!System.BaseData</InputType>
</WriteActionModuleType>