Too many SQL connections






Quote:

We have  many SQL 2000 server, that is not setup as a distributor or a    

publisher. It is not involved in replication. we we have been seeing a bunch of connections on the server from user NT AUTHORITY/SYSTEM application SQLDMO executing exec sp_helpdistpublisher @check_user = 1 a number of times. Why would it be doing that, when the server is not setup for replication. One more thing.. We have MOM2005 SP1 would this be related.. ??





I’m getting the same problem. After installing the new SQL MP the connections arn’t released. So I started the query analyzer. Exec a sp_who2. The process names where all SQLDMO_ and the SQL statement was  exec sp_helpdistpublisher @check_user = 1 . I started a SQL profiles and monitored the server for a while. Then i did a search string with “exec sp_helpdistpublisher @check_user = 1”. On the match record i looked at the “clientProcessID” . Then i looked in the system task manager what process has this PID. And yes it was the “MOMHost.exe”. So YES it is MOM releated. I’m going to see whats the solution. 


Found it on the inet:






Quote:


RESOLUTION:

To resolve the issue, you changed the contents of the SQL Server 2000
Replication Monitoring script with the contents of the one from the original
SQL 2000 MP (version 05.0.2746.0000). Since then, the process is now being
released.






Ok this solves the problem. I pasted the 05.0.2746.0000 script below:






‘——————————————————————-
‘ <company>Microsoft Corporation</company>
‘ <copyright>Copyright (c) Microsoft Corporation 2003</copyright>
‘ <summary>
‘&nbsp;&nbsp; Alerts on Replication failures
‘ </summary>
‘——————————————————————-


option explicit


‘Event Constants
Const EVENTID_INFORMATION = 10701


Const PROBLEMSTATE_NOTSET = 0
Const PROBLEMSTATE_GREEN = 1
Const PROBLEMSTATE_GREY = 2
Const PROBLEMSTATE_RED = 3



Const ALERT_SUCCESS = 10
Const ALERT_INFORMATION = 20
Const ALERT_WARNING = 30
Const ALERT_ERROR = 40
Const ALERT_CRITICAL_ERROR = 50
Const ALERT_SECURITY_BREACH = 60
Const ALERT_SERVICE_UNAVAILABLE = 70



‘Other constants
Const SCRIPT_NAME = “SQL Server 2000 Replication Failures”


Dim g_oSQL


Sub Main()


&nbsp;Dim oParams, bInformationEvent, aInstances, sMsgActive
&nbsp;Dim i, sMessage, oEvent


&nbsp;Set g_oSQL = New SQL


&nbsp;Set oParams = ScriptContext.Parameters
&nbsp;bInformationEvent = CBool(oParams.Get(“InformationEvent”))
&nbsp;Set oParams = Nothing


&nbsp;aInstances = Split(g_oSQL.GetSQLInstances(),”,”)
&nbsp;For i = 0 To UBound(aInstances)
&nbsp;&nbsp;If sMsgActive <> “” Then sMsgActive = sMsgActive & “,”&nbsp;&nbsp;
&nbsp;&nbsp;sMsgActive = sMsgActive & aInstances(i)


&nbsp;&nbsp;CheckReplicationFailures aInstances(i)
&nbsp;Next
&nbsp;
&nbsp;If bInformationEvent Then
&nbsp;&nbsp;If sMsgActive <> “” Then
&nbsp;&nbsp;&nbsp;sMessage = “The script ‘” & SCRIPT_NAME & “‘ ran.&nbsp; The following instances are available on this server and were checked: ” & sMsgActive
&nbsp;&nbsp;Else
&nbsp;&nbsp;&nbsp;sMessage = “The script ‘” & SCRIPT_NAME & “‘ ran.&nbsp; There were no instances currently active on this server”
&nbsp;&nbsp;End If
&nbsp;&nbsp;g_oSQL.CreateEvent EVENTID_INFORMATION, EVENT_TYPE_INFORMATION, sMessage
&nbsp;&nbsp;&nbsp; End If


End Sub



‘******************************************************************************
‘ Name:&nbsp;&nbsp;CheckReplicationFailures

‘ Purpose:&nbsp;Checks for replication failures

‘ Parameters:&nbsp;sInstance – the name of the instance to check

‘ Returns:&nbsp;nothing

Function CheckReplicationFailures(sInstance)
&nbsp;dim cnADOConnection
&nbsp;dim rsSQLReplicationFailures
&nbsp;dim strServerName
&nbsp;dim strProv
&nbsp;dim strQuery
&nbsp;dim strDatabaseName
&nbsp;dim sName
&nbsp;dim spath
&nbsp;dim sMessage


&nbsp;strDatabaseName = “distribution”
&nbsp;
&nbsp;On Error Resume Next


&nbsp;sName = g_oSQL.GetSQLName(sInstance)


&nbsp;If sName <> “” Then


&nbsp;&nbsp;If sInstance = “MSSQLSERVER” Then
&nbsp;&nbsp;sPath = sName
&nbsp;&nbsp;Else
&nbsp;&nbsp;sPath = sName & “” & sInstance
&nbsp;&nbsp;End If


&nbsp;&nbsp;Set cnADOConnection = MomCreateObject(“ADODB.Connection”)
&nbsp;&nbsp;cnADOConnection.Provider = “sqloledb”
&nbsp;&nbsp;cnADOConnection.ConnectionTimeout = 30
&nbsp;&nbsp;strProv = “Server=” & sPath & “;Database=” & strDatabaseName & “;Trusted_Connection=yes”


&nbsp;&nbsp;on error resume next
&nbsp;&nbsp;Err.Clear
&nbsp;&nbsp;cnADOConnection.Open strProv
&nbsp;&nbsp;if 0 <> Err.number then
&nbsp;&nbsp;&nbsp;on error goto 0
&nbsp;&nbsp;&nbsp;Set cnADOConnection = Nothing
&nbsp;&nbsp;&nbsp;Exit Function
&nbsp;&nbsp;end if
&nbsp;&nbsp;on error goto 0


&nbsp;&nbsp;’SELECT
&nbsp;&nbsp;’&nbsp;dbo.MSdistribution_history.agent_id,
&nbsp;&nbsp;’&nbsp;dbo.MSdistribution_history.runstatus,
&nbsp;&nbsp;’&nbsp;dbo.MSdistribution_history.[time],
&nbsp;&nbsp;’&nbsp;dbo.MSdistribution_history.comments,
&nbsp;&nbsp;’&nbsp;dbo.MSdistribution_agents.name
&nbsp;&nbsp;’FROM
&nbsp;&nbsp;’&nbsp;dbo.MSdistribution_history INNER JOIN
&nbsp;&nbsp;’&nbsp;dbo.MSdistribution_agents ON dbo.MSdistribution_history.agent_id = dbo.MSdistribution_agents.id
&nbsp;&nbsp;’WHERE&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;’&nbsp;(dbo.MSdistribution_history.runstatus = ‘6’) AND
&nbsp;&nbsp;’&nbsp;DATEDIFF(minute, [time], getdate()) < 10&nbsp;
&nbsp;&nbsp;strQuery = “SELECT dbo.MSdistribution_history.agent_id, dbo.MSdistribution_history.runstatus, dbo.MSdistribution_history.[time], dbo.MSdistribution_history.comments, dbo.MSdistribution_agents.name FROM dbo.MSdistribution_history INNER JOIN dbo.MSdistribution_agents ON dbo.MSdistribution_history.agent_id = dbo.MSdistribution_agents.id WHERE (dbo.MSdistribution_history.runstatus = ‘6’) AND DATEDIFF(minute, [time], getdate()) < 20”


&nbsp;&nbsp;Set rsSQLReplicationFailures = cnADOConnection.Execute(strQuery)


&nbsp;&nbsp;Do While rsSQLReplicationFailures.EOF = False


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sMessage = “The SQL Server Replication Agent (” & rsSQLReplicationFailures(“name”).Value & “) has failed. Details: ” & rsSQLReplicationFailures(“comments”).Value
&nbsp;&nbsp;&nbsp;g_oUtil.LogMessage g_oUtil.DBG_TRACE, sMessage


&nbsp;&nbsp;&nbsp;g_oSQL.CreateAlert ALERT_CRITICAL_ERROR, _
&nbsp;&nbsp;&nbsp;&nbsp;SCRIPT_NAME, _
&nbsp;&nbsp;&nbsp;&nbsp;sMessage, _
&nbsp;&nbsp;&nbsp;&nbsp;””, _
&nbsp;&nbsp;&nbsp;&nbsp;””


&nbsp;&nbsp;&nbsp;rsSQLReplicationFailures.MoveNext
&nbsp;&nbsp;Loop


&nbsp;End If


&nbsp;Set cnADOConnection = Nothing
&nbsp;Set rsSQLReplicationFailures = Nothing
End Function


Dim g_aDatabaseExcludeArray
Dim g_bDatabaseExclusion
Dim g_aJobExcludeArray
Dim g_bJobExclusion


&nbsp;


&nbsp;


Const SQL_CLASS_ID = “SQL”


Const SQL_SQL_SERVER_INSTANCE_NAME_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “SQL Server Instance Name”
Const SQL_AUDIT_LEVEL_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Audit Level”
Const SQL_AUTHENTICATION_MODE_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Authentication Mode”
Const SQL_CLUSTER_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Cluster”
Const SQL_CONNECTION_NAME_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Connection Name”
Const SQL_ENABLE_ERROR_REPORTING_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Enable Error Reporting”
Const SQL_ERROR_LOG_LOCATION_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Error Log Location”
Const SQL_LANGUAGE_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Language”
Const SQL_MASTER_DATABASE_LOCATION_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Master Database Location”
Const SQL_MASTER_DATABASE_LOG_LOCATION_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Master Database Log Location”
Const SQL_REPLICATION_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Replication”
Const SQL_REPLICATION_DISTRIBUTION_DATABASE_ATTRIBUTE_ID =&nbsp; “Replication Distribution Database”
Const SQL_REPLICATION_WORKING_DIRECTORY_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Replication Working Directory”
Const SQL_SERVICE_NAME_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Service Name”
Const SQL_SERVICE_PACK_VERSION_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Service Pack Version”
Const SQL_SQL_SERVER_VERSION_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “SQL Server Version”
Const SQL_AGENT_NAME_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Agent Name”
Const SQL_INSTALL_PATH_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Install Path”
Const SQL_TOOLS_PATH_ATTRIBUTE_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Tools Path”


Const SQL_LOG_SPACE_COMPONENT_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Log Space”
Const SQL_DB_HEALTH_COMPONENT_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “DB Health”
Const SQL_AGENT_COMPONENT_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Agent”
Const SQL_CONNECTIVITY_COMPONENT_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “Connectivity”
Const SQL_DB_SPACE_COMPONENT_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “DB Space”
Const SQL_SQL_COMPONENT_ID =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; “SQL”


&nbsp;


&nbsp;


‘******************************************************************************
‘ Name – SQL – SQL Server Utility Class

‘ Version – Microsoft Operations Manager 2005

‘ Purpose – Utility Class for SQL Server health monitoring

‘ Methods Implemented –

‘ Discovery and Service Check:
‘&nbsp;&nbsp;GetSQLInstances&nbsp;&nbsp;- Returns a comma-delimited list of SQL instances
‘&nbsp;&nbsp;IsSQL7&nbsp;&nbsp;&nbsp;&nbsp;- Returns True if SQL Server 7.0
‘&nbsp;&nbsp;Is64Bit&nbsp;&nbsp;&nbsp;&nbsp;- Returns True if 64Bit
‘&nbsp;&nbsp;IsMSDE&nbsp;&nbsp;&nbsp;&nbsp;- Returns True if MSDE
‘&nbsp;&nbsp;IsClustered&nbsp;&nbsp;&nbsp;- Returns boolean for SQL clustered value
‘&nbsp;&nbsp;IsServiceStarted&nbsp;- Checks if the specified service is started
‘&nbsp;&nbsp;GetSQLName&nbsp;&nbsp;&nbsp;- Returns the name of the SQL Server&nbsp;
‘&nbsp;&nbsp;GetSQLInstanceName&nbsp;- Returns the SQL Server instance name
‘&nbsp;&nbsp;CollectDatabaseExclusions&nbsp;- Collect a list of excluded servers
‘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CollectJobExclusions&nbsp;&nbsp;&nbsp; – Collect a list of excluded jobs
‘&nbsp;&nbsp;IsDatabaseExcluded&nbsp;&nbsp;&nbsp;- Determine if a database is excluded
‘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IsJobExcluded&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; – Determine if a job is excluded
‘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IsSQLServiceStarted – Checks if the specified SQL server instance is started
‘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSQLServiceName&nbsp;&nbsp; – Returns the service name for a SQL instance
‘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetConnectionFailureMessage – Returns an error message for connection failures
‘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetRunningInstances&nbsp; – Returns arrays of the instances in a given array that are running and not running

‘ Connectivity Check:
‘&nbsp;&nbsp;SQLConnect&nbsp;&nbsp;&nbsp;- Checks if a specified instance returns data

‘ Event Logging:
‘&nbsp;&nbsp;CreateEvent&nbsp;&nbsp;&nbsp;- Creates a MOM event
‘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CreateAlert&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; – Creates a MOM alert

‘ Service Discovery:
‘&nbsp;&nbsp;ServiceStateUpdate&nbsp;- Updates the Summary State View for a specified SRG

‘ Registry Reading:&nbsp;&nbsp;
‘&nbsp;&nbsp;ReadRegistryStringValue&nbsp;- Read a string registry key
‘&nbsp;&nbsp;ReadRegistryMultiStringValue – Read a multi string registry key
‘&nbsp;&nbsp;ReadRegistryDWORDValue – Read a DWORD value registry key
‘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSQLInstanceKeyRoot – Get the root of the sql instance’s registry keys
‘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSQLInstanceKey&nbsp;&nbsp;&nbsp;&nbsp; – Get the registry key path for a sql instance
‘&nbsp;&nbsp;
‘ Version 12


Class SQL
&nbsp;
&nbsp; Public HKEY_LOCAL_MACHINE
&nbsp; Public SQL_DEFAULT
&nbsp; Public SQL_KEY_DEFAULT
&nbsp; Public SQL_KEY_NAMED
&nbsp; Public SQL_KEY_VER
&nbsp; Public SQL_VAL_INSTINST
&nbsp;
&nbsp; Public SERVICESTATE_GREEN
&nbsp; Public SERVICESTATE_YELLOW
&nbsp; Public SERVICESTATE_RED
&nbsp;
&nbsp; Public DATABASE_EXCLUDE_FILENAME
&nbsp; Public DATABASE_EXCLUDE_DIRECTORY
&nbsp; Public JOB_EXCLUDE_FILENAME
&nbsp; Public JOB_EXCLUDE_DIRECTORY
&nbsp;
&nbsp; Private m_oSafeRegistry
&nbsp;
‘******************************************************************************
‘ Name:&nbsp;&nbsp;Class_Initialize

‘ Purpose:&nbsp;Initialize the public methods of the class&nbsp;

‘ Parameters:&nbsp;None

‘ Returns:&nbsp;None

Private Sub Class_Initialize()


&nbsp;&nbsp;&nbsp; HKEY_LOCAL_MACHINE = &H80000002
&nbsp;&nbsp;&nbsp; SQL_DEFAULT = “MSSQLSERVER”
&nbsp;&nbsp;&nbsp; SQL_KEY_DEFAULT = “SoftwareMicrosoftMSSQLServer”
&nbsp;&nbsp;&nbsp; SQL_KEY_NAMED = “SoftwareMicrosoftMicrosoft SQL Server”
&nbsp;&nbsp;&nbsp; SQL_KEY_VER = “SoftwareMicrosoftMSSQLServerMSSQLServerCurrentVersion”
&nbsp;&nbsp;&nbsp; SQL_VAL_INSTINST = “InstalledInstances”


&nbsp;&nbsp;&nbsp; SERVICESTATE_GREEN = 0
&nbsp;&nbsp;&nbsp; SERVICESTATE_YELLOW = 1
&nbsp;&nbsp;&nbsp; SERVICESTATE_RED = 2
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; DATABASE_EXCLUDE_FILENAME = “SQLExclude.txt”
&nbsp;&nbsp;&nbsp; DATABASE_EXCLUDE_DIRECTORY = “C:”
&nbsp;&nbsp;&nbsp; JOB_EXCLUDE_FILENAME = “SQLMPAgentExclude.txt”
&nbsp;&nbsp;&nbsp; JOB_EXCLUDE_DIRECTORY = “C:”


&nbsp;&nbsp;&nbsp; Set m_oSafeRegistry = New SafeRegistry
&nbsp;&nbsp;&nbsp; m_oSafeRegistry.SuppressionFlags = (m_oSafeRegistry.SUPPRESS_KEY_NOT_FOUND Or m_oSafeRegistry.SUPPRESS_VALUE_NOT_FOUND)
&nbsp;&nbsp;&nbsp;
End Sub


‘******************************************************************************
‘ Name:&nbsp;&nbsp;GetRunningInstances

‘ Purpose:&nbsp;

‘ Parameters:&nbsp;

‘ Returns:&nbsp;

Public Function GetRunningInstances(ByVal aInstances, ByRef aNonRunningInstances)


&nbsp;&nbsp;&nbsp; Dim sWQLNameList
&nbsp;&nbsp;&nbsp; Dim sInstance
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; If Not IsArray(aInstances) Then Exit Function
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; For Each sInstance In aInstances
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If sWQLNameList <> “” Then sWQLNameList = sWQLNameList & ” or “
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sWQLNameList = sWQLNameList & “Name = ‘” & GetSQLServiceName(sInstance) & “‘”
&nbsp;&nbsp;&nbsp; Next
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; If sWQLNameList <> “” Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim sWQLQuery
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sWQLQuery = “select Name from Win32_Service where (” & sWQLNameList & “)”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim sNamespace
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sNamespace = “winmgmts://” & ScriptContext.TargetComputer & “/root/cimv2”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim oRunning
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set oRunning = WMIExecQuery(sNamespace, sWQLQuery & ” and State = ‘Running'”)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetRunningInstances = CreateSQLInstanceArray(oRunning)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim oNotRunning
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set oNotRunning = WMIExecQuery(sNamespace, sWQLQuery & ” and State <> ‘Running'”)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; aNonRunningInstances = CreateSQLInstanceArray(oNotRunning)
&nbsp;&nbsp;&nbsp; End If


End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;CreateSQLInstanceArray

‘ Purpose:&nbsp;

‘ Parameters:&nbsp;

‘ Returns:&nbsp;

Private Function CreateSQLInstanceArray(ByVal oServiceObjectSet)
&nbsp;&nbsp;&nbsp; Dim aInstances
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; If oServiceObjectSet.Count > 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReDim aInstances(oServiceObjectSet.Count – 1)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim i
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim oService
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each oService in oServiceObjectSet
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; aInstances(i) = GetSQLInstanceNameFromServiceName(oService.Name)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = i + 1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next
&nbsp;&nbsp;&nbsp; End If


&nbsp;&nbsp;&nbsp; CreateSQLInstanceArray = aInstances&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;GetSQLInstanceKeyRoot

‘ Purpose:&nbsp;Gets the path to the root registry key for the instance’s
‘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; registry values

‘ Parameters:&nbsp;sInstance – The SQL instance name

‘ Returns:&nbsp;the root registry path

Public Function GetSQLInstanceKeyRoot(ByVal sInstance)
&nbsp;&nbsp;&nbsp; If sInstance = SQL_DEFAULT Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSQLInstanceKeyRoot = SQL_KEY_DEFAULT
&nbsp;&nbsp;&nbsp; Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSQLInstanceKeyRoot = SQL_KEY_NAMED & “” & sInstance
&nbsp;&nbsp;&nbsp; End If
End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;GetSQLInstanceKey

‘ Purpose:&nbsp;Gets the path to the registry key for the instance

‘ Parameters:&nbsp;sInstance – The SQL instance name

‘ Returns:&nbsp;the registry path

Public Function GetSQLInstanceKey(ByVal sInstance, ByVal sKey)
&nbsp;&nbsp;&nbsp; GetSQLInstanceKey = GetSQLInstanceKeyRoot(sInstance) & “” & sKey
End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;GetConnectionFailureMessage

‘ Purpose:&nbsp;To generate a message stating the reason for failing to connect to a SQL instance

‘ Parameters:&nbsp;sInstance, The SQL instance
‘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lErrNumber, The error number returned from the connection attempt
‘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sErrDescription, The error description returned from the connection attempt

‘ Returns:&nbsp;The failure message

Public Function GetConnectionFailureMessage(sInstance, lErrNumber, sErrDescription)
&nbsp;&nbsp;&nbsp; Dim sFailureReason
&nbsp;&nbsp;&nbsp; Dim sSQLServiceName
&nbsp;&nbsp;&nbsp; sSQLServiceName = GetSQLServiceName(sInstance)
&nbsp;&nbsp;&nbsp; Dim sResult


&nbsp;&nbsp;&nbsp; Select Case IsSQLServiceStarted(sInstance)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case -2
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sFailureReason = “is not installed”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case -1, 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sFailureReason = “is not running”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case 1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Const DB_CONNECTION_FAILURE_MESSAGE = “The SQL Server management pack script “”SQL Server 2000 Replication Monitoring”” is unable to successfully connect to the SQL Server instance “”{ServiceName}””. The error message returned is “”{Description}”””
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sResult = Replace(DB_CONNECTION_FAILURE_MESSAGE, “{ServiceName}”, sSQLServiceName)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetConnectionFailureMessage = Replace(sResult, “{Description}”, sErrDescription)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Function
&nbsp;&nbsp;&nbsp; End Select


&nbsp;&nbsp;&nbsp; Const DB_CONNECTION_NO_SERVICE_MESSAGE = “The SQL Server service ({ServiceName}) {FailureReason}.”
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; sResult = Replace(DB_CONNECTION_NO_SERVICE_MESSAGE, “{ServiceName}”, sSQLServiceName)
&nbsp;&nbsp;&nbsp; GetConnectionFailureMessage = Replace(sResult, “{FailureReason}”, sFailureReason)
End Function



‘******************************************************************************
‘ Name:&nbsp;&nbsp;GetSQLInstances

‘ Purpose:&nbsp;Gets the list of instances of SQL installed on
‘&nbsp;&nbsp;the specified server.&nbsp; These are read from the registry.

‘ Parameters:&nbsp;None

‘ Returns:&nbsp;A comma separated list of instances

Public Function GetSQLInstances()


&nbsp;Dim sInstances
&nbsp;Dim aKeyValues
&nbsp;Dim iCount
&nbsp;&nbsp;&nbsp; Dim sClusterName
&nbsp;&nbsp;&nbsp; Dim bAddInstance
&nbsp;&nbsp;&nbsp; Dim sInstance
&nbsp;&nbsp;&nbsp;
&nbsp;aKeyValues = ReadRegistryMultiStringValue(SQL_KEY_NAMED, SQL_VAL_INSTINST, ScriptContext.TargetComputer)
&nbsp;&nbsp;
&nbsp;If Not IsNull(aKeyValues) Then
&nbsp;&nbsp;For Each sInstance In aKeyValues
&nbsp;&nbsp;&nbsp;If Not IsMSDE(sInstance) Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sClusterName = ReadRegistryStringValue(GetSQLInstanceKey(sInstance, “Cluster”), “ClusterName”, ScriptContext.TargetComputer)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If ScriptContext.IsTargetVirtualServer Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bAddInstance = (ScriptContext.TargetNetbiosComputer = sClusterName)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bAddInstance = IsNull(sClusterName)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If bAddInstance Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If sInstances <> “” Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sInstances = sInstances & “,”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sInstances = sInstances & sInstance
&nbsp;&nbsp;&nbsp;&nbsp;End If
&nbsp;&nbsp;&nbsp;End If
&nbsp;&nbsp;Next
&nbsp;Else
&nbsp;&nbsp;If IsSQL7(ScriptContext.TargetComputer) then
&nbsp;&nbsp;&nbsp;sInstances = SQL_DEFAULT
&nbsp;&nbsp;Else
&nbsp;&nbsp;&nbsp;sInstances = “”
&nbsp;&nbsp;End If
&nbsp;End If


&nbsp;Call g_oUtil.LogMessage(g_oUtil.DBG_TRACE, “GetSQLInstances returning the following instances: ” & sInstances)


&nbsp;GetSQLInstances = sInstances


End Function



‘******************************************************************************
‘ Name:&nbsp;&nbsp;IsSQL7

‘ Purpose:&nbsp;Checks if a Server is SQL Server 7.0

‘ Parameters:&nbsp;sHostName, the name of the instance to check

‘ Returns:&nbsp;True if Microsoft SQL Server 7.0 is installed
‘&nbsp;&nbsp;&nbsp;False if Microsoft SQL Server 7.0 is not installed

Public Function IsSQL7(sHostName)


&nbsp;If Left(ReadRegistryStringValue(SQL_KEY_VER, “CurrentVersion”, ScriptContext.TargetComputer),4) = “7.00” Then
&nbsp;&nbsp;IsSQL7 = True
&nbsp;&nbsp;Call g_oUtil.LogMessage(g_oUtil.DBG_TRACE, “SQL Server 7.0 True for: ” & sHostName)
&nbsp;Else
&nbsp;&nbsp;IsSQL7 = False
&nbsp;End if


End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;Is64Bit

‘ Purpose:&nbsp;Checks if a Server is 64Bit

‘ Parameters:&nbsp;sInstance, the name of the instance to check

‘ Returns:&nbsp;True if 64Bit
‘&nbsp;&nbsp;&nbsp;False if not 64bit
Public Function Is64Bit(sInstance)


&nbsp; Dim sKeyValue
&nbsp;
&nbsp; sKeyValue = ReadRegistryStringValue(GetSQLInstanceKey(SQL_DEFAULT, “Setup”), “FeatureName”, ScriptContext.TargetComputer)
&nbsp;
&nbsp; If sKeyValue = “SQL_Engine” Then
&nbsp;&nbsp;&nbsp; Is64Bit = True
&nbsp;&nbsp;&nbsp; Call g_oUtil.LogMessage(g_oUtil.DBG_TRACE, “64Bit True for: ” & sInstance)
&nbsp; Else
&nbsp;&nbsp;&nbsp; Is64Bit = False
&nbsp; End If


End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;IsMSDE

‘ Purpose:&nbsp;Checks if a Server is MSDE

‘ Parameters:&nbsp;sInstance, the name of the instance to check

‘ Returns:&nbsp;True if Microsoft MSDE
‘&nbsp;&nbsp;&nbsp;False if Microsoft MSDE is not installed
Public Function IsMSDE(sInstance)


&nbsp; Dim sKeyValue
&nbsp;
&nbsp; if True = Is64Bit(sInstance) then
&nbsp;IsMSDE = False
&nbsp;Exit Function
&nbsp; End if
&nbsp;
&nbsp; sKeyValue = ReadRegistryStringValue(GetSQLInstanceKey(sInstance, “Setup”), “ProductCode”, ScriptContext.TargetComputer)
&nbsp;
&nbsp; If Not IsNull(sKeyValue) Then
&nbsp;&nbsp;&nbsp; IsMSDE = True
&nbsp;&nbsp;&nbsp; Call g_oUtil.LogMessage(g_oUtil.DBG_TRACE, “MSDE True for: ” & sInstance)
&nbsp; Else
&nbsp;&nbsp;&nbsp; IsMSDE = False
&nbsp; End If


End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;IsClustered

‘ Purpose:&nbsp;Checks if an instance is clustered

‘ Parameters:&nbsp;sInstance, the name of the instance to check

‘ Returns:&nbsp;1 if the instance is clustered
‘&nbsp;&nbsp;0 if the instance is not clustered


Public Function IsClustered(sInstance)


&nbsp; Dim sClusterName
&nbsp;
&nbsp; sClusterName = ReadRegistryStringValue(GetSQLInstanceKey(sInstance, “Cluster”), “ClusterName”, ScriptContext.TargetComputer)
&nbsp; If Not IsNull(sClusterName) Then
&nbsp;&nbsp;&nbsp; IsClustered = 1
&nbsp;&nbsp;&nbsp; Call g_oUtil.LogMessage(g_oUtil.DBG_TRACE, “The following node is a member of a cluster: ” & sInstance)
&nbsp; Else
&nbsp;&nbsp;&nbsp; IsClustered = 0
&nbsp; End If
&nbsp;
End Function



‘******************************************************************************
‘ Name:&nbsp;&nbsp;IsSQLServiceStarted

‘ Purpose:&nbsp;Checks whether a given SQL service instance is running&nbsp;&nbsp;

‘ Parameters:&nbsp;sInstance, the name of the SQL instance to check

‘ Returns:&nbsp;0 if the service is not started and not disabled
‘&nbsp;&nbsp;&nbsp;1 if the service is started
‘&nbsp;&nbsp;&nbsp;-1 if the service is not started but the service is disabled
‘&nbsp;&nbsp;&nbsp;-2 if there was a WMI Error getting the service status or the
‘&nbsp;&nbsp;&nbsp;&nbsp;service does not exist


Public Function IsSQLServiceStarted(sInstance)
&nbsp;&nbsp;&nbsp; IsSQLServiceStarted = IsServiceStarted(GetSQLServiceName(sInstance))
End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;IsServiceStarted

‘ Purpose:&nbsp;Checks whether a given Windows service is running&nbsp;&nbsp;

‘ Parameters:&nbsp;sServiceName, the Windows service name (short)

‘ Returns:&nbsp;0 if the service is not started and not disabled
‘&nbsp;&nbsp;&nbsp;1 if the service is started
‘&nbsp;&nbsp;&nbsp;-1 if the service is not started but the service is disabled
‘&nbsp;&nbsp;&nbsp;-2 if there was a WMI Error getting the service status or the
‘&nbsp;&nbsp;&nbsp;&nbsp;service does not exist


Public Function IsServiceStarted(sServiceName)


&nbsp; Dim oService, sObjectString
&nbsp;
&nbsp; sObjectString = “winmgmts:” & ScriptContext.TargetComputer & “rootcimv2”
&nbsp;&nbsp;&nbsp;
&nbsp; On Error Resume Next
&nbsp; Err.Clear
&nbsp; ‘We want to do our own error handling here. No WMIGetObject().
&nbsp; Set oService = GetObject(sObjectString & “:Win32_Service.Name='” & sServiceName & “‘”)
&nbsp; If Err.number <> 0 Then
&nbsp;&nbsp;&nbsp; IsServiceStarted = -2
&nbsp; Else
&nbsp;&nbsp;&nbsp; If oService.State = “Running” Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IsServiceStarted = 1
&nbsp;&nbsp;&nbsp; ElseIf oService.StartMode = “Disabled” Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IsServiceStarted = -1
&nbsp;&nbsp;&nbsp; Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IsServiceStarted = 0
&nbsp;&nbsp;&nbsp; End If
&nbsp; End If
&nbsp; Set oService = nothing
&nbsp; On Error Goto 0
&nbsp;
End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;GetSQLInstanceNameFromServiceName

‘ Purpose:&nbsp;

‘ Parameters:&nbsp;

‘ Returns:&nbsp;

Public Function GetSQLInstanceNameFromServiceName(ByVal sServiceName)
&nbsp;&nbsp;&nbsp; If sServiceName = SQL_DEFAULT Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSQLInstanceNameFromServiceName = SQL_DEFAULT
&nbsp;&nbsp;&nbsp; Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSQLInstanceNameFromServiceName = Mid(sServiceName, 7)
&nbsp;&nbsp;&nbsp; End If
End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;GetSQLServiceName

‘ Purpose:&nbsp;

‘ Parameters:&nbsp;sInstance, the name of the instance to return the service name for

‘ Returns:&nbsp;The service name


Public Function GetSQLServiceName(sInstance)
&nbsp;&nbsp;&nbsp; If sInstance = SQL_DEFAULT Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSQLServiceName = SQL_DEFAULT
&nbsp;&nbsp;&nbsp; Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSQLServiceName = “MSSQL$” & sInstance
&nbsp;&nbsp;&nbsp; End If
End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;GetSQLName

‘ Purpose:&nbsp;Returns the name of the SQL server.&nbsp; This will be the physical
‘&nbsp;&nbsp;name of the server for a non clustered instance.&nbsp; It will be the
‘&nbsp;&nbsp;Virtual name for a clustered instance

‘ Parameters:&nbsp;sInstance, the name of the instance to return the name for

‘ Returns:&nbsp;The server name (virtual or physical)
‘&nbsp;&nbsp;If there was an error getting the name “” is returned


Public Function GetSQLName(sInstance)
&nbsp; Dim sClusterName


&nbsp; If IsClustered(sInstance) Then
&nbsp;&nbsp;&nbsp; sClusterName = ReadRegistryStringValue(GetSQLInstanceKey(sInstance, “Cluster”), “ClusterName”, ScriptContext.TargetComputer)
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; If Not IsNull(sClusterName) Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSQLName = sClusterName
&nbsp;&nbsp;&nbsp; Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSQLName = “”
&nbsp;&nbsp;&nbsp; End If
&nbsp;
&nbsp; Else
&nbsp;&nbsp;&nbsp; GetSQLName = ScriptContext.TargetComputer&nbsp;&nbsp;&nbsp;
&nbsp; End If


Call g_oUtil.LogMessage(g_oUtil.DBG_TRACE, “GetSQLName returns: ” & GetSQLName)


End Function



‘******************************************************************************
‘ Name:&nbsp;&nbsp;GetSQLInstanceName

‘ Purpose:&nbsp;Returns the SQL Server instance name or default

‘ Parameters:&nbsp;sName – The physical name of the SQL Server
‘&nbsp;&nbsp;&nbsp;&nbsp;sInstance – The SQL Server instance name&nbsp;&nbsp;&nbsp;&nbsp;

‘ Returns:&nbsp;The default or named instance connection name

Public Function GetSQLInstanceName(sName, sInstance)


&nbsp;&nbsp;&nbsp; If sInstance = SQL_DEFAULT Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSQLInstanceName = sName
&nbsp;&nbsp;&nbsp; Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetSQLInstanceName = sName & “” & sInstance
&nbsp;&nbsp;&nbsp; End If


End Function



‘******************************************************************************
‘ Name:&nbsp;&nbsp;SQLConnect

‘ Purpose:&nbsp;Creates a SQL DMO connection to an instance and runs a query
‘&nbsp;&nbsp;at the instance level

‘ Parameters:&nbsp;sInstance, the name of the instance to check
‘&nbsp;&nbsp;
‘ Returns:&nbsp;1 if a connection is successfully made and the query run
‘&nbsp;&nbsp;&nbsp;0 if a connection cannot be made or the query cannot be run

Public Function SQLConnect(sInstance)


&nbsp; dim oSQLServer, sPath, oResults, sName


&nbsp; On Error Resume Next


&nbsp; sName = GetSQLName (sInstance)
&nbsp; If sName <> “” Then


&nbsp;&nbsp;&nbsp; Set oSQLServer = MomCreateObject(“SQLDMO.SQLServer”)
&nbsp;&nbsp;&nbsp; If Err.number = 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oSQLServer.LoginSecure = 1


&nbsp;&nbsp; sPath = GetSQLInstanceName(sName, sInstance)


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oSQLServer.Connect sPath
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Err.Number = 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set oResults = oSQLServer.ExecuteWithResults(“SELECT GETDATE()”)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Err.Number =&nbsp; 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If oResults.GetColumnString(1,1) <> “” Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQLConnect = 1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQLConnect = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQLConnect = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oSQLServer.Disconnect
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set oSQLServer = Nothing
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set oResults = nothing
&nbsp;&nbsp;&nbsp; Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQLConnect = 0
&nbsp;&nbsp;&nbsp; End If
&nbsp; Else
&nbsp;&nbsp;&nbsp; SQLConnect = 0
&nbsp; End If


&nbsp; On Error Goto 0
&nbsp;
End Function



‘******************************************************************************
‘ Name:&nbsp;&nbsp;CreateEvent

‘ Purpose:&nbsp;Creates an event and inserts it into the MOM data stream
‘&nbsp;&nbsp;The event will be created with the source set to the script name

‘ Parameters:&nbsp;iEventID, the event ID
‘&nbsp;&nbsp;iEventType, the event type (see constant values at top of file)
‘&nbsp;&nbsp;sMessage, the message text for the event


Public Sub CreateEvent(iEventID, iEventType, sMessage)
&nbsp; On Error Resume Next


&nbsp; Dim oNewEvent


&nbsp; ‘ Create a new event
&nbsp; Set oNewEvent = ScriptContext.CreateEvent()


&nbsp; ‘ Set event properties
&nbsp; oNewEvent.Message = sMessage
&nbsp; oNewEvent.EventNumber = iEventID
&nbsp; oNewEvent.EventType = iEventType


&nbsp; ‘ Submit the event
&nbsp; ScriptContext.Submit oNewEvent


&nbsp; Set oNewEvent = Nothing


End Sub


”******************************************************************************
‘ Name:&nbsp;&nbsp;CreateAlert

‘ Purpose:&nbsp;Raises an alert

‘ Parameters:
‘&nbsp;iSeverity – The severity of the alert.
‘&nbsp;strName – The name of the alert.
‘&nbsp;strDescription – The alert description.
‘&nbsp;strInstance – The instance of SQL for which to issue an alert.
‘&nbsp;&nbsp; strComponent – The SQL component affected

Function CreateAlert(iSeverity, strName, strDescription, strInstance, strComponent)
&nbsp;Dim oAlert
&nbsp;
&nbsp;Set oAlert = ScriptContext.CreateAlert()
&nbsp;
&nbsp;oAlert.Name = strName
&nbsp;oAlert.Description = strDescription
&nbsp;oAlert.AlertSource = “SQL Server 2000 Replication Monitoring”
&nbsp;oAlert.AlertLevel = iSeverity
&nbsp;
&nbsp;If strInstance <> “” And strComponent <> “” Then
&nbsp;&nbsp;&nbsp;&nbsp; oAlert.ProblemState = PROBLEMSTATE_RED
&nbsp;&nbsp;&nbsp;&nbsp; oAlert.ServerRole = SQL_CLASS_ID
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAlert.ServerRoleInstance = strInstance
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAlert.Component = strComponent
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oAlert.ComponentInstance = “”
&nbsp;&nbsp;&nbsp; End If


&nbsp;ScriptContext.Submit oAlert
End Function


&nbsp;


‘******************************************************************************
‘ Name:&nbsp;&nbsp;CollectDatabaseExclusions

‘ Purpose:&nbsp;Collect the list of excluded databases

‘ Parameters:&nbsp;None

‘ Returns:&nbsp;None

Sub CollectDatabaseExclusions()


&nbsp;Dim oExcludeFile
&nbsp;Dim oFSO
&nbsp;Dim sExcludeDatabaseName
&nbsp;
&nbsp;On Error Resume Next
&nbsp;
&nbsp;Set oFSO = MomCreateObject(“Scripting.FileSystemObject”)
&nbsp;Set oExcludeFile = oFSO.OpenTextFile(DATABASE_EXCLUDE_DIRECTORY & DATABASE_EXCLUDE_FILENAME, 1)
&nbsp;
&nbsp;If Err.number = 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Call g_oUtil.LogMessage(g_oUtil.DBG_TRACE, “Exclusions are defined for this server”)
&nbsp;&nbsp;g_bDatabaseExclusion = True
&nbsp;&nbsp;sExcludeDatabaseName = oExcludeFile.ReadAll
&nbsp;&nbsp;g_aDatabaseExcludeArray = Split(sExcludeDatabaseName, vbcrlf)
&nbsp;&nbsp;oExcludeFile.Close
&nbsp;Else
&nbsp;&nbsp;g_bDatabaseExclusion = False
&nbsp;End If


&nbsp;&nbsp;&nbsp; On Error Goto 0&nbsp;
End Sub



‘******************************************************************************
‘ Name:&nbsp;&nbsp;IsDatabaseExcluded

‘ Purpose:&nbsp;Determine if a specified database is exlcuded from monitoring

‘ Parameters:&nbsp;Instance name and Database name

‘ Returns:&nbsp;True or False

Function IsDatabaseExcluded(sInstanceName, sDatabaseName)


&nbsp;Dim sInstanceDatabaseName
&nbsp;Dim iArrayMembers
&nbsp;
&nbsp;If g_bDatabaseExclusion Then
&nbsp;&nbsp;If sInstanceName = SQL_DEFAULT Then
&nbsp;&nbsp;&nbsp;sInstanceDatabaseName = sDatabaseName
&nbsp;&nbsp;Else
&nbsp;&nbsp;&nbsp;sInstanceDatabaseName = sInstanceName & “” & sDatabaseName
&nbsp;&nbsp;End If


&nbsp;&nbsp;For iArrayMembers = 0 To UBound(g_aDatabaseExcludeArray)


&nbsp;&nbsp;&nbsp;If UCase(g_aDatabaseExcludeArray(iArrayMembers)) = UCase(sInstanceDatabaseName) Then
&nbsp;&nbsp;&nbsp;&nbsp;IsDatabaseExcluded = True
&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Call g_oUtil.LogMessage(g_oUtil.DBG_TRACE, “Database ” & sDatabaseName & “on instance ” & sInstanceName & ” is excluded”)
&nbsp;&nbsp;&nbsp;&nbsp;Exit Function
&nbsp;&nbsp;&nbsp;End If&nbsp;
&nbsp;&nbsp;Next
&nbsp;&nbsp;
&nbsp;&nbsp;IsDatabaseExcluded = False
&nbsp;Else
&nbsp;&nbsp;IsDatabaseExcluded = False
&nbsp;End If


End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;CollectJobExclusions

‘ Purpose:&nbsp;Collect the list of excluded servers/jobs

‘ Parameters:&nbsp;None

‘ Returns:&nbsp;None

Sub CollectJobExclusions()


&nbsp;Dim oExcludeFile
&nbsp;Dim oFSO
&nbsp;Dim sExcludeServerName
&nbsp;
&nbsp;On Error Resume Next
&nbsp;
&nbsp;Set oFSO = MomCreateObject(“Scripting.FileSystemObject”)
&nbsp;Set oExcludeFile = oFSO.OpenTextFile(JOB_EXCLUDE_DIRECTORY & JOB_EXCLUDE_FILENAME, 1)
&nbsp;
&nbsp;If Err.number = 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Call g_oUtil.LogMessage(g_oUtil.DBG_TRACE, “Exclusions are defined for this server”)
&nbsp;&nbsp;g_bJobExclusion = True
&nbsp;&nbsp;sExcludeServerName = oExcludeFile.ReadAll
&nbsp;&nbsp;g_aJobExcludeArray = Split(sExcludeServerName, vbcrlf)
&nbsp;&nbsp;oExcludeFile.Close
&nbsp;Else
&nbsp;&nbsp;g_bJobExclusion = False
&nbsp;End If


&nbsp;&nbsp;&nbsp; On Error Goto 0&nbsp;
End Sub



‘******************************************************************************
‘ Name:&nbsp;&nbsp;IsJobExcluded

‘ Purpose:&nbsp;Determine if a specified server/job is exlcuded from monitoring

‘ Parameters:&nbsp;Server name and Job name

‘ Returns:&nbsp;True or False

Function IsJobExcluded(sServerName, sJobName)
&nbsp;Dim sServerJobName
&nbsp;Dim iArrayMembers
&nbsp;
&nbsp;If g_bJobExclusion Then
&nbsp;&nbsp;sServerJobName = sServerName & “” & sJobName


&nbsp;&nbsp;For iArrayMembers = 0 To UBound(g_aJobExcludeArray)


&nbsp;&nbsp;&nbsp;If UCase(g_aJobExcludeArray(iArrayMembers)) = UCase(sServerJobName) Then
&nbsp;&nbsp;&nbsp;&nbsp;IsJobExcluded = True
&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Call g_oUtil.LogMessage(g_oUtil.DBG_TRACE, “Job ” & sJobName & “on server ” & sServerName & ” is excluded”)
&nbsp;&nbsp;&nbsp;&nbsp;Exit Function
&nbsp;&nbsp;&nbsp;End If&nbsp;
&nbsp;&nbsp;Next
&nbsp;&nbsp;
&nbsp;&nbsp;IsJobExcluded = False
&nbsp;Else
&nbsp;&nbsp;IsJobExcluded = False
&nbsp;End If


End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;ServiceStateUpdate

‘ Purpose:&nbsp;Generate State Monitoring Red and Green lights for Summary State View

‘ Parameters:&nbsp;sStateToUpdate – eg Agent, Server, Connectivity
‘&nbsp;&nbsp;&nbsp;&nbsp;sServiceName – name of the instance eg Instance1, Instance2
‘&nbsp;&nbsp;&nbsp;&nbsp;sStateDescription – text to be included in the alert description
‘&nbsp;&nbsp;&nbsp;&nbsp;sHealthState – defined by constants

‘ Returns:&nbsp;Nothing


Public Function ServiceStateUpdate(sStateToUpdate, sServiceName, sStateSource, sStateDescription, iHealthState)


&nbsp;Dim lngProblemState
&nbsp;Dim oAlert
&nbsp;Dim iProblemState
&nbsp;Dim iAlertSev


&nbsp;Set oAlert = ScriptContext.CreateAlert()
&nbsp;
&nbsp;oAlert.Description = sStateDescription
&nbsp;oAlert.AlertSource =&nbsp; sStateSource
&nbsp;
&nbsp;oAlert.ServerRole = SQL_CLASS_ID
&nbsp;oAlert.ServerRoleInstance = sServiceName


&nbsp;Select Case sStateToUpdate
&nbsp;&nbsp;Case “Server”
&nbsp;&nbsp;&nbsp;oAlert.Name = “SQL Server 2000 Service Availability”
&nbsp;&nbsp;&nbsp;oAlert.Component = SQL_SQL_COMPONENT_ID
&nbsp;&nbsp;Case “Agent”
&nbsp;&nbsp;&nbsp;oAlert.Name = “SQL Server Agent Service Availability”
&nbsp;&nbsp;&nbsp;oAlert.Component = SQL_AGENT_COMPONENT_ID
&nbsp;&nbsp;Case “Connectivity”
&nbsp;&nbsp;&nbsp;oAlert.Name = “SQL Server Local Connectivity”
&nbsp;&nbsp;&nbsp;oAlert.Component = SQL_CONNECTIVITY_COMPONENT_ID
&nbsp;&nbsp;Case “DatabaseHealth”
&nbsp;&nbsp;&nbsp;oAlert.Name = “SQL Server 2000 Database Health”
&nbsp;&nbsp;&nbsp;oAlert.Component = SQL_DB_HEALTH_COMPONENT_ID
&nbsp;&nbsp;Case “DatabaseSpace”
&nbsp;&nbsp;&nbsp;oAlert.Name = “SQL Server Database Space”
&nbsp;&nbsp;&nbsp;oAlert.Component = SQL_DB_SPACE_COMPONENT_ID
&nbsp;&nbsp;Case “LogSpace”
&nbsp;&nbsp;&nbsp;oAlert.Name = “SQL Server Log Space”
&nbsp;&nbsp;&nbsp;oAlert.Component = SQL_LOG_SPACE_COMPONENT_ID
&nbsp;End Select
&nbsp;
&nbsp;Select Case iHealthState
&nbsp;&nbsp;Case SERVICESTATE_GREEN
&nbsp;&nbsp;&nbsp;iProblemState = PROBLEMSTATE_GREEN
&nbsp;&nbsp;&nbsp;iAlertSev = ALERT_CRITICAL_ERROR
&nbsp;&nbsp;Case SERVICESTATE_YELLOW
&nbsp;&nbsp;&nbsp;iProblemState = PROBLEMSTATE_RED
&nbsp;&nbsp;&nbsp;iAlertSev = ALERT_WARNING
&nbsp;&nbsp;Case SERVICESTATE_RED
&nbsp;&nbsp;&nbsp;iProblemState = PROBLEMSTATE_RED
&nbsp;&nbsp;&nbsp;iAlertSev = ALERT_CRITICAL_ERROR
&nbsp;End Select


&nbsp;oAlert.ProblemState = iProblemState
&nbsp;oAlert.AlertLevel = iAlertSev
&nbsp;ScriptContext.Submit oAlert&nbsp;


End Function



‘******************************************************************************
‘ Name:&nbsp;&nbsp;ReadRegistryStringValue

‘ Purpose:&nbsp;Return a string value from the registry (HKLM)

‘ Parameters:&nbsp;sKeyPath, the path to the key
‘&nbsp;&nbsp;&nbsp;&nbsp;sValueName, the name of the value to return
‘&nbsp;&nbsp;&nbsp;&nbsp;sHostName, the computer to connect to

‘ Returns:&nbsp;A string matching the contents of the value or null

Public Function ReadRegistryStringValue(sKeyPath, sValueName, sHostName)
&nbsp;&nbsp;&nbsp; Dim lResult
&nbsp;&nbsp;&nbsp; ReadRegistryStringValue = m_oSafeRegistry.ReadStringValue(sKeyPath, sValueName, sHostName, lResult)
End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;ReadRegistryMultiStringValue

‘ Purpose:&nbsp;Return a multi string value from the registry (HKLM)

‘ Parameters:&nbsp;sKeyPath, the path to the key
‘&nbsp;&nbsp;&nbsp;&nbsp;sValueName, the name of the value to return
‘&nbsp;&nbsp;&nbsp;&nbsp;sHostName, the computer to connect to

‘ Returns:&nbsp;A string matching the contents of the value or null

Public Function ReadRegistryMultiStringValue(sKeyPath, sValueName, sHostName)
&nbsp;&nbsp;&nbsp; Dim lResult
&nbsp;&nbsp;&nbsp; ReadRegistryMultiStringValue = m_oSafeRegistry.ReadMultiStringValue(sKeyPath, sValueName, sHostName, lResult)
End Function


‘******************************************************************************
‘ Name:&nbsp;&nbsp;ReadRegistryDWORDValue

‘ Purpose:&nbsp;Return a DWORD value from the registry (HKLM)

‘ Parameters:&nbsp;sKeyPath, the path to the key
‘&nbsp;&nbsp;&nbsp;&nbsp;sValueName, the name of the value to return
‘&nbsp;&nbsp;&nbsp;&nbsp;sHostName, the computer to connect to

‘ Returns:&nbsp;A string matching the contents of the value or null

Public Function ReadRegistryDWORDValue(sKeyPath, sValueName, sHostName)
&nbsp;&nbsp;&nbsp; Dim lResult
&nbsp;&nbsp;&nbsp; ReadRegistryDWORDValue = m_oSafeRegistry.ReadDWORDValue(sKeyPath, sValueName, sHostName, lResult)
End Function


End Class



Class SafeRegistry
&nbsp;&nbsp;&nbsp; Private m_oError
&nbsp;&nbsp;&nbsp; Private m_oRegistry
&nbsp;&nbsp;&nbsp; Private m_sHive
&nbsp;&nbsp;&nbsp; Public SUPPRESS_KEY_NOT_FOUND
&nbsp;&nbsp;&nbsp; Public SUPPRESS_VALUE_NOT_FOUND
&nbsp;&nbsp;&nbsp; Public SUPPRESS_ACCESS_DENIED
&nbsp;&nbsp;&nbsp; Public SUPPRESS_ALL
&nbsp;&nbsp;&nbsp; Private m_lSuppressionFlags
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; Private Sub Class_Initialize()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set m_oError = New Error
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_sHive = “HKLM”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set m_oRegistry = New Registry
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SUPPRESS_KEY_NOT_FOUND = &H00000001
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SUPPRESS_VALUE_NOT_FOUND = &H00000002
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SUPPRESS_ACCESS_DENIED = &H00000004
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SUPPRESS_ALL = &HFFFFFFFF
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_lSuppressionFlags = 0
&nbsp;&nbsp;&nbsp; End Sub
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; Public Property Let SuppressionFlags(ByVal lValue)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_lSuppressionFlags = lValue
&nbsp;&nbsp;&nbsp; End Property
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; Public Property Get SuppressionFlags()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SuppressionFlags = m_lSuppressionFlags
&nbsp;&nbsp;&nbsp; End Property
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; Public Function ReadDWORDValue(ByVal sKeyPath, ByVal sValueName, ByVal sHostName, ByRef lResult)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReadDWORDValue = Null
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; On Error Resume Next
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReadDWORDValue = m_oRegistry.ReadDWORDValue(sKeyPath, sValueName, sHostName, lResult)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_oError.Save
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; On Error Goto 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If m_oError.Number <> 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThrowScriptErrorNoAbort GET_ERROR_READING_REGISTRY_MESSAGE(m_sHive, sKeyPath, sValueName), m_oError
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Function
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HandleResult m_sHive, sKeyPath, sValueName, lResult
&nbsp;&nbsp;&nbsp; End Function
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; Public Function ReadStringValue(ByVal sKeyPath, ByVal sValueName, ByVal sHostName, ByRef lResult)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReadStringValue = Null
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; On Error Resume Next
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReadStringValue = m_oRegistry.ReadStringValue(sKeyPath, sValueName, sHostName, lResult)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_oError.Save
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; On Error Goto 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If m_oError.Number <> 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThrowScriptErrorNoAbort GET_ERROR_READING_REGISTRY_MESSAGE(m_sHive, sKeyPath, sValueName), m_oError
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Function
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HandleResult m_sHive, sKeyPath, sValueName, lResult
&nbsp;&nbsp;&nbsp; End Function


&nbsp;&nbsp;&nbsp; Public Function ReadMultiStringValue(ByVal sKeyPath, ByVal sValueName, ByVal sHostName, ByRef lResult)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReadMultiStringValue = Null
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; On Error Resume Next
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReadMultiStringValue = m_oRegistry.ReadMultiStringValue(sKeyPath, sValueName, sHostName, lResult)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_oError.Save
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; On Error Goto 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If m_oError.Number <> 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThrowScriptErrorNoAbort GET_ERROR_READING_REGISTRY_MESSAGE(m_sHive, sKeyPath, sValueName), m_oError
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Function
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HandleResult m_sHive, sKeyPath, sValueName, lResult
&nbsp;&nbsp;&nbsp; End Function
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; Public Function EnumKeys(ByVal sKeyPath, ByVal sHostName, ByRef lResult)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EnumKeys = Null
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; On Error Resume Next
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EnumKeys = m_oRegistry.EnumKeys(sKeyPath, sHostName, lResult)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_oError.Save
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; On Error Goto 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If m_oError.Number <> 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThrowScriptErrorNoAbort GET_ERROR_READING_KEY_MESSAGE(m_sHive, sKeyPath), m_oError
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Function
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HandleResult m_sHive, sKeyPath, “”, lResult
&nbsp;&nbsp;&nbsp; End Function
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; Private Sub HandleResult(ByVal sHive, ByVal sKeyPath, ByVal sValueName, ByVal lResult)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select Case lResult
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case m_oRegistry.SUCCESS
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case m_oRegistry.ERROR_ACCESS_DENIED
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If (SuppressionFlags And SUPPRESS_ACCESS_DENIED) = 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThrowScriptErrorNoAbort GET_REGISTRY_ACCESS_DENIED_MESSAGE(sHive, sKeyPath, sValueName), Err
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ScriptContext.Echo GET_REGISTRY_ACCESS_DENIED_MESSAGE(sHive, sKeyPath, sValueName)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case m_oRegistry.ERROR_VALUE_NOT_FOUND
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If (SuppressionFlags And SUPPRESS_VALUE_NOT_FOUND) = 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThrowScriptErrorNoAbort GET_REGISTRY_VALUE_NOT_FOUND_MESSAGE(sHive, sKeyPath, sValueName), Err
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ScriptContext.Echo GET_REGISTRY_VALUE_NOT_FOUND_MESSAGE(sHive, sKeyPath, sValueName)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case m_oRegistry.ERROR_KEY_NOT_FOUND
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If (SuppressionFlags And SUPPRESS_KEY_NOT_FOUND) = 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThrowScriptErrorNoAbort GET_REGISTRY_KEY_NOT_FOUND_MESSAGE(sHive, sKeyPath), Err
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ScriptContext.Echo GET_REGISTRY_KEY_NOT_FOUND_MESSAGE(sHive, sKeyPath)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If (SuppressionFlags And SUPPRESS_ALL) = 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThrowScriptErrorNoAbort GET_ERROR_READING_REGISTRY_MESSAGE(sHive, sKeyPath, sValueName), Err
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ScriptContext.Echo GET_ERROR_READING_REGISTRY_MESSAGE(sHive, sKeyPath, sValueName)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Select
&nbsp;&nbsp;&nbsp; End Sub
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; Private Function GET_REGISTRY_ACCESS_DENIED_MESSAGE(ByVal sHive, ByVal sRegKey, ByVal sRegValue)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Const REGISTRY_ACCESS_DENIED_MESSAGE = “Access denied while reading registry value [{Hive}{RegKey}{RegValue}]”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim sResult
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sResult = Replace(REGISTRY_ACCESS_DENIED_MESSAGE, “{RegKey}”, sRegKey)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sResult = Replace(sResult, “{Hive}”, sHive)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GET_REGISTRY_ACCESS_DENIED_MESSAGE = Replace(sResult, “{RegValue}”, sRegValue)
&nbsp;&nbsp;&nbsp; End Function


&nbsp;&nbsp;&nbsp; Private Function GET_REGISTRY_VALUE_NOT_FOUND_MESSAGE(ByVal sHive, ByVal sRegKey, ByVal sRegValue)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Const REGISTRY_VALUE_NOT_FOUND_MESSAGE = “Registry value [{Hive}{RegKey}{RegValue}] not found”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim sResult
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sResult = Replace(REGISTRY_VALUE_NOT_FOUND_MESSAGE, “{RegKey}”, sRegKey)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sResult = Replace(sResult, “{Hive}”, sHive)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GET_REGISTRY_VALUE_NOT_FOUND_MESSAGE = Replace(sResult, “{RegValue}”, sRegValue)
&nbsp;&nbsp;&nbsp; End Function


&nbsp;&nbsp;&nbsp; Private Function GET_ERROR_READING_REGISTRY_MESSAGE(ByVal sHive, ByVal sRegKey, ByVal sRegValue)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Const ERROR_READING_REGISTRY_MESSAGE = “Error while reading registry value [{Hive}{RegKey}{RegValue}]”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim sResult
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sResult = Replace(ERROR_READING_REGISTRY_MESSAGE, “{RegKey}”, sRegKey)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sResult = Replace(sResult, “{Hive}”, sHive)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GET_ERROR_READING_REGISTRY_MESSAGE = Replace(sResult, “{RegValue}”, sRegValue)
&nbsp;&nbsp;&nbsp; End Function


&nbsp;&nbsp;&nbsp; Function GET_REGISTRY_KEY_NOT_FOUND_MESSAGE(ByVal sHive, ByVal sRegKey)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Const REGISTRY_KEY_NOT_FOUND_MESSAGE = “Registry key [{Hive}{RegKey}] not found”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim sResult
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sResult = Replace(REGISTRY_KEY_NOT_FOUND_MESSAGE, “{Hive}”, sHive)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GET_REGISTRY_KEY_NOT_FOUND_MESSAGE = Replace(sResult, “{RegKey}”, sRegKey)
&nbsp;&nbsp;&nbsp; End Function


&nbsp;&nbsp;&nbsp; Function GET_ERROR_READING_KEY_MESSAGE(ByVal sHive, ByVal sRegKey)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Const ERROR_READING_KEY_MESSAGE = “Error while reading registry key [{Hive}{RegKey}]”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim sResult
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sResult = Replace(ERROR_READING_KEY_MESSAGE, “{Hive}”, sHive)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GET_ERROR_READING_KEY_MESSAGE = Replace(sResult, “{RegKey}”, sRegKey)
&nbsp;&nbsp;&nbsp; End Function
End Class


Class Registry
&nbsp;&nbsp;&nbsp; Private HKEY_CLASSES_ROOT
&nbsp;&nbsp;&nbsp; Private HKEY_CURRENT_USER
&nbsp;&nbsp;&nbsp; Private HKEY_LOCAL_MACHINE
&nbsp;&nbsp;&nbsp; Private HKEY_USERS
&nbsp;&nbsp;&nbsp; Private HKEY_CURRENT_CONFIG
&nbsp;&nbsp;&nbsp; Private HKEY_DYN_DATA


&nbsp;&nbsp;&nbsp; Public ERROR_ACCESS_DENIED
&nbsp;&nbsp;&nbsp; Public ERROR_KEY_NOT_FOUND
&nbsp;&nbsp;&nbsp; Public ERROR_VALUE_NOT_FOUND
&nbsp;&nbsp;&nbsp; Public SUCCESS
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; Private Sub Class_Initialize()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HKEY_CLASSES_ROOT = &H80000000
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HKEY_CURRENT_USER = &H80000001
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HKEY_LOCAL_MACHINE = &H80000002
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HKEY_USERS = &H80000003
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HKEY_CURRENT_CONFIG = &H80000005
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HKEY_DYN_DATA = &H80000006
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ERROR_ACCESS_DENIED = 5
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ERROR_KEY_NOT_FOUND = 2
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ERROR_VALUE_NOT_FOUND = 1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SUCCESS = 0
&nbsp;&nbsp;&nbsp; End Sub
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; Public Function ReadDWORDValue(ByVal sKeyPath, ByVal sValueName, ByVal sHostName, ByRef lResult)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim oReg
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set oReg = WMIGetObject(“winmgmts://” & sHostName & “/root/default:StdRegProv”)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim lValue
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lResult = oReg.GetDWORDValue(HKEY_LOCAL_MACHINE, sKeyPath, sValueName, lValue)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReadDWORDValue = lValue
&nbsp;&nbsp;&nbsp; End Function
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; Public Function ReadStringValue(ByVal sKeyPath, ByVal sValueName, ByVal sHostName, ByRef lResult)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim oReg
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set oReg = WMIGetObject(“winmgmts://” & sHostName & “/root/default:StdRegProv”)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim sValue
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lResult = oReg.GetStringValue(HKEY_LOCAL_MACHINE, sKeyPath, sValueName, sValue)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReadStringValue = sValue
&nbsp;&nbsp;&nbsp; End Function
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; Public Function ReadMultiStringValue(ByVal sKeyPath, ByVal sValueName, ByVal sHostName, ByRef lResult)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim oReg
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set oReg = WMIGetObject(“winmgmts://” & sHostName & “/root/default:StdRegProv”)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim aValues
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lResult = oReg.GetMultiStringValue(HKEY_LOCAL_MACHINE, sKeyPath, sValueName, aValues)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReadMultiStringValue = aValues
&nbsp;&nbsp;&nbsp; End Function
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; Public Function EnumKeys(ByVal sKeyPath, ByVal sHostName, ByRef lResult)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim oReg
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set oReg = WMIGetObject(“winmgmts://” & sHostName & “/root/default:StdRegProv”)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim aSubKeys
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lResult = oReg.EnumKey(HKEY_LOCAL_MACHINE, sKeyPath, aSubKeys)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EnumKeys = aSubKeys
&nbsp;&nbsp;&nbsp; End Function
End Class


&nbsp;


Class Error
&nbsp;&nbsp;&nbsp; Private m_lNumber
&nbsp;&nbsp;&nbsp; Private m_sSource
&nbsp;&nbsp;&nbsp; Private m_sDescription
&nbsp;&nbsp;&nbsp; Private m_sHelpContext
&nbsp;&nbsp;&nbsp; Private m_sHelpFile
&nbsp;&nbsp;&nbsp; Public Sub Save()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_lNumber = Err.number
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_sSource = Err.Source
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_sDescription = Err.Description
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_sHelpContext = Err.HelpContext
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_sHelpFile = Err.helpfile
&nbsp;&nbsp;&nbsp; End Sub
&nbsp;&nbsp;&nbsp; Public Sub Raise()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Err.Raise m_lNumber, m_sSource, m_sDescription, m_sHelpFile, m_sHelpContext
&nbsp;&nbsp;&nbsp; End Sub
&nbsp;&nbsp;&nbsp; Public Sub Clear()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_lNumber = 0
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_sSource = “”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_sDescription = “”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_sHelpContext = “”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_sHelpFile = “”
&nbsp;&nbsp;&nbsp; End Sub
&nbsp;&nbsp;&nbsp; Public Property Get Number()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Number = m_lNumber
&nbsp;&nbsp;&nbsp; End Property
&nbsp;&nbsp;&nbsp; Public Property Get Source()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Source = m_sSource
&nbsp;&nbsp;&nbsp; End Property
&nbsp;&nbsp;&nbsp; Public Property Get Description()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description = m_sDescription
&nbsp;&nbsp;&nbsp; End Property
&nbsp;&nbsp;&nbsp; Public Property Get HelpContext()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelpContext = m_sHelpContext
&nbsp;&nbsp;&nbsp; End Property
&nbsp;&nbsp;&nbsp; Public Property Get HelpFile()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelpFile = m_sHelpFile
&nbsp;&nbsp;&nbsp; End Property&nbsp;&nbsp;&nbsp;
End Class


&nbsp;


Dim g_oUtil
Set g_oUtil = New Util


‘==========================================================================
‘ Class:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Util
‘ Description:&nbsp; Utility methods for logging, creating MOM alert
‘==========================================================================
Class Util


&nbsp;’ Used to say to LogMessage when/how to print the message.
&nbsp;Public DBG_NONE
&nbsp;Public DBG_ERROR
&nbsp;Public DBG_WARNING
&nbsp;Public DBG_TRACE
&nbsp;Public HKEY_LOCAL_MACHINE


&nbsp;’Internal Debug Level
&nbsp;Private m_nDebugLevel&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; Private m_oSafeRegistry
&nbsp;’—————
&nbsp;’ Methods
&nbsp;’—————


&nbsp;’=============
&nbsp;’ Method:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Class_Initialize
&nbsp;’ Description:&nbsp; This is the constructor
&nbsp;’ Parameters:
&nbsp;’=============
&nbsp;Private Sub Class_Initialize()
&nbsp;&nbsp;’ Initialize Debug level constants
&nbsp;&nbsp;DBG_TRACE = 1
&nbsp;&nbsp;DBG_WARNING = 2
&nbsp;&nbsp;DBG_ERROR = 3
&nbsp;&nbsp;DBG_NONE = 4


&nbsp;&nbsp;’by default only errors are logged
&nbsp;&nbsp;m_nDebugLevel = DBG_ERROR
&nbsp;&nbsp;
&nbsp;&nbsp;Set m_oSafeRegistry = New SafeRegistry
&nbsp;&nbsp;m_oSafeRegistry.SuppressionFlags = (m_oSafeRegistry.SUPPRESS_KEY_NOT_FOUND Or m_oSafeRegistry.SUPPRESS_VALUE_NOT_FOUND)


&nbsp;End Sub
&nbsp;
&nbsp;’=============
&nbsp;’ Method:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Class_Terminate
&nbsp;’ Description:&nbsp; This is the destructor
&nbsp;’ Parameters:
&nbsp;’=============
&nbsp;Private Sub Class_Terminate()
&nbsp;End Sub


&nbsp;’=============
&nbsp;’ Method:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetDebugLevel
&nbsp;’ Description:&nbsp; To change the debugging output level of information
&nbsp;’&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; generated by this utility.
&nbsp;’ Parameters:
&nbsp;’&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nLevel – Level, either DBG_NONE, DBG_TRACE,
&nbsp;’&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DBG_WARNING or DBG_ERROR
&nbsp;’=============
&nbsp;Public Sub SetDebugLevel(ByVal nLevel)
&nbsp;&nbsp;&nbsp;m_nDebugLevel = nLevel
&nbsp;End Sub
&nbsp;
&nbsp;’=============
&nbsp;’ Method:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LogMessage
&nbsp;’ Description:&nbsp; Log a debug message to ScriptContext
&nbsp;’ Parameters:
&nbsp;’&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nLevel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; – Debug level for the message that we’re logging.
&nbsp;’&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strMessage&nbsp; – The message to write to the trace.
&nbsp;’=============
&nbsp;Public Sub LogMessage( _
&nbsp;&nbsp;ByVal nLevel, _
&nbsp;&nbsp;ByVal strMessage _
&nbsp;&nbsp;)
&nbsp;&nbsp;If (nLevel >= m_nDebugLevel) Then
&nbsp;&nbsp;&nbsp;if (nLevel = DBG_ERROR) Then
&nbsp;&nbsp;&nbsp;&nbsp;ScriptContext.Echo “[Error]: ” & strMessage
&nbsp;&nbsp;&nbsp;ElseIf (nLevel = DBG_WARNING) Then
&nbsp;&nbsp;&nbsp;&nbsp;ScriptContext.Echo “[Warning]: ” & strMessage
&nbsp;&nbsp;&nbsp;ElseIf (nLevel = DBG_TRACE) Then
&nbsp;&nbsp;&nbsp;&nbsp;ScriptContext.Echo “[Trace]:” & strMessage
&nbsp;&nbsp;&nbsp;End If
&nbsp;&nbsp;End If
&nbsp;End Sub
&nbsp;
&nbsp;’=============
&nbsp;’ Method:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SplitVerStr
&nbsp;’ Description:&nbsp; Split a version string into integers.
&nbsp;’ Parameters:
&nbsp;’&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strVer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; – The version string.
&nbsp;’&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iMajor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; – The output integer for major version.
&nbsp;’&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iMinor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; – The output integer for minor version.
&nbsp;’=============
&nbsp;Function SplitVerStr(ByVal strVer, ByRef iMajor, ByRef iMinor)
&nbsp;&nbsp;Dim iPos
&nbsp;&nbsp;Dim strMinor
&nbsp;&nbsp;
&nbsp;&nbsp;iPos = InStr(strVer, “.”)
&nbsp;&nbsp;
&nbsp;&nbsp;if 0 = iPos then
&nbsp;&nbsp;&nbsp;iMajor = CInt(strVer)
&nbsp;&nbsp;&nbsp;iMinor = 0
&nbsp;&nbsp;&nbsp;Exit Function
&nbsp;&nbsp;end if
&nbsp;&nbsp;
&nbsp;&nbsp;iMajor = CInt(Left(strVer, iPos))
&nbsp;&nbsp;strMinor = Right(strVer, Len(strVer)-iPos)
&nbsp;&nbsp;
&nbsp;&nbsp;iPos = InStr(strMinor, “.”)
&nbsp;&nbsp;
&nbsp;&nbsp;if 0 = iPos then
&nbsp;&nbsp;&nbsp;iMinor = CInt(strMinor)
&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;iMinor = CInt(Left(strMinor, iPos))
&nbsp;&nbsp;end if


&nbsp;End Function


&nbsp;’=============
&nbsp;’ Method:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReadRegistryValue
&nbsp;’ Description:&nbsp; Used to read strings from the registry
&nbsp;’ Parameters:
&nbsp;’&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Root&nbsp;&nbsp;- Root of the registry (HKEY_LOCAL_MACHINE, HKEY_USERS etc. Refer to constants defined earlier)
&nbsp;’&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strKeyPath&nbsp;- Key path for the Registry key to read
&nbsp;’&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (like “SOFTWAREMicrosoftWindowsNTCurrentVersion”)
&nbsp;’&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strValueName – Name of the registry entry to read (like “SoftwareType”)
&nbsp;’&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;’ Returns:
&nbsp;’&nbsp;&nbsp;&nbsp;&nbsp;The value of the registry key specified. “Nothing” if it fails. Callee needs to handle null value return.
&nbsp;’=============
&nbsp;Public Function ReadRegistryValue(strKeyPath, strValueName, strHostName)
&nbsp;&nbsp;&nbsp;&nbsp; Dim lResult
&nbsp;&nbsp;&nbsp;&nbsp; Dim strValueData
&nbsp;&nbsp;&nbsp;&nbsp; strValueData = m_oSafeRegistry.ReadStringValue(strKeyPath, strValueName, strHostName, lResult)
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;If Not IsNull(strValueData) Then
&nbsp;&nbsp;&nbsp;Call LogMessage(DBG_TRACE, “Value of Registry Key: ” & strKeyPath & “” & strValueName & ” = ” & strValueData)
&nbsp;&nbsp;&nbsp;ReadRegistryValue = strValueData
&nbsp;&nbsp;Else
&nbsp;&nbsp;&nbsp;Call LogMessage(DBG_ERROR, “Reading Registry Key: ” & strKeyPath & “” & strValueName & ” Failed!” )
&nbsp;&nbsp;&nbsp;ReadRegistryValue = empty
&nbsp;&nbsp;End If
&nbsp;End Function
&nbsp;
End Class


&nbsp;


&nbsp;



Function IsValidObject(ByVal oObject)
&nbsp;&nbsp;&nbsp; IsValidObject = False
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; If IsObject(oObject) Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not oObject Is Nothing Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IsValidObject = True
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If
&nbsp;&nbsp;&nbsp; End If
End Function&nbsp;


Function WMIGetObject(sNamespace)

‘ WMIGetObject :: Returns the WMI object requested.


&nbsp;Dim oWMI


&nbsp;On Error Resume Next
&nbsp;Set oWMI = GetObject(sNamespace)
&nbsp;If IsEmpty(oWMI) Then
&nbsp;&nbsp;ThrowScriptError “Unable to open WMI Namespace ‘” & sNamespace & “‘.&nbsp; Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists.”, Err
&nbsp;End If
&nbsp;On Error Goto 0


&nbsp;Set WMIGetObject = oWMI
&nbsp;Set oWMI = Nothing


End Function


Function WMIGetInstance(sNamespace, sInstance)

‘ WMIGetInstance :: Returns WMI Instance requested.


&nbsp;Dim oWMI, oInstance, nInstanceCount


&nbsp;On Error Resume Next
&nbsp;Set oWMI = GetObject(sNamespace)
&nbsp;If IsEmpty(oWMI) Then
&nbsp;&nbsp;ThrowScriptError “Unable to open WMI Namespace ‘” & sNamespace & “‘.&nbsp; Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists.”, Err
&nbsp;End If


&nbsp;Set oInstance = oWMI.InstancesOf(sInstance)
&nbsp;If IsEmpty(oInstance) Or Err.Number <> 0 Then
&nbsp;&nbsp;ThrowScriptError “The class name ‘” & sInstance & “‘ returned no instances.&nbsp; Please check to see if this is a valid WMI class name.”, Err
&nbsp;End If


&nbsp;’Determine if we queried a valid WMI class – Count will return 0 or empty


&nbsp;nInstanceCount = oInstance.Count
&nbsp;If Err.Number <> 0 Then
&nbsp;&nbsp;ThrowScriptError “The class name ‘” & sInstance & “‘ did not return any valid instances.&nbsp; Please check to see if this is a valid WMI class name.”, Err
&nbsp;End If
&nbsp;On Error Goto 0


&nbsp;Set WMIGetInstance = oInstance


&nbsp;Set oInstance = Nothing
&nbsp;Set oWMI = Nothing


End Function


Function WMIExecQuery(sNamespace, sQuery)

‘ WMIExecQuery :: Executes the WMI query and returns the result set.


&nbsp;Dim oWMI, oQuery, nInstanceCount
&nbsp;
&nbsp;On Error Resume Next
&nbsp;Set oWMI = GetObject(sNamespace)
&nbsp;If IsEmpty(oWMI) Then
&nbsp;&nbsp;ThrowScriptError “Unable to open WMI Namespace ‘” & sNamespace & “‘.&nbsp; Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists.”, Err
&nbsp;End If


&nbsp;Set oQuery = oWMI.ExecQuery(sQuery)
&nbsp;If IsEmpty(oQuery) Or Err.Number <> 0 Then
&nbsp;&nbsp;ThrowScriptError “The Query ‘” & sQuery & “‘ returned an invalid result set.&nbsp; Please check to see if this is a valid WMI Query.”, Err
&nbsp;End If


&nbsp;’Determine if we queried a valid WMI class – Count will return 0 or empty
&nbsp;nInstanceCount = oQuery.Count
&nbsp;If Err.Number <> 0 Then
&nbsp;&nbsp;ThrowScriptError “The Query ‘” & sQuery & “‘ did not return any valid instances.&nbsp; Please check to see if this is a valid WMI Query.”, Err
&nbsp;End If
&nbsp;On Error Goto 0


&nbsp;Set WMIExecQuery = oQuery


&nbsp;Set oQuery = Nothing
&nbsp;Set oWMI = Nothing
End Function


&nbsp;


Function WMIGetInstanceNoAbort(sNamespace, sInstance)

‘ WMIGetInstanceNoAbort :: Returns WMI Instance requested.


&nbsp;Dim oWMI, oInstance, nInstanceCount


&nbsp;On Error Resume Next
&nbsp;Set oWMI = GetObject(sNamespace)
&nbsp;If Not IsEmpty(oWMI) Then


&nbsp;&nbsp;Set oInstance = oWMI.InstancesOf(sInstance)
&nbsp;&nbsp;If Not IsEmpty(oInstance) And Err.Number = 0 Then


&nbsp;&nbsp;&nbsp;’Determine if we queried a valid WMI class – Count will return 0 or empty
&nbsp;&nbsp;&nbsp;nInstanceCount = oInstance.Count
&nbsp;&nbsp;&nbsp;If Err.Number = 0 Then
&nbsp;&nbsp;&nbsp;&nbsp;Set WMIGetInstanceNoAbort = oInstance
&nbsp;&nbsp;&nbsp;&nbsp;Exit Function
&nbsp;&nbsp;&nbsp;End If
&nbsp;&nbsp;End If
&nbsp;End If
&nbsp;On Error Goto 0


&nbsp;Set WMIGetInstanceNoAbort = Nothing


&nbsp;Set oInstance = Nothing
&nbsp;Set oWMI = Nothing


End Function


&nbsp;



Const wbemCimtypeUseDefault = 0&nbsp;&nbsp; ‘Use Default Type CIM type – Custom
Const wbemCimtypeSint16&nbsp;&nbsp;&nbsp;&nbsp; = 2&nbsp;&nbsp; ‘Signed 16-bit integer
Const wbemCimtypeSint32&nbsp;&nbsp;&nbsp;&nbsp; = 3&nbsp;&nbsp; ‘Signed 32-bit integer
Const wbemCimtypeReal32&nbsp;&nbsp;&nbsp;&nbsp; = 4&nbsp;&nbsp; ’32-bit real number
Const wbemCimtypeReal64&nbsp;&nbsp;&nbsp;&nbsp; = 5&nbsp;&nbsp; ’64-bit real number
Const wbemCimtypeString&nbsp;&nbsp;&nbsp;&nbsp; = 8&nbsp;&nbsp; ‘String
Const wbemCimtypeBoolean&nbsp;&nbsp;&nbsp; = 11&nbsp; ‘Boolean value
Const wbemCimtypeObject&nbsp;&nbsp;&nbsp;&nbsp; = 13&nbsp; ‘CIM object
Const wbemCimtypeSint8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 16&nbsp; ‘Signed 8-bit integer
Const wbemCimtypeUint8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 17&nbsp; ‘Unsigned 8-bit integer
Const wbemCimtypeUint16&nbsp;&nbsp;&nbsp;&nbsp; = 18&nbsp; ‘Unsigned 16-bit integer
Const wbemCimtypeUint32&nbsp;&nbsp;&nbsp;&nbsp; = 19&nbsp; ‘Unsigned 32-bit integer
Const wbemCimtypeSint64&nbsp;&nbsp;&nbsp;&nbsp; = 20&nbsp; ‘Signed 64-bit integer&nbsp;
Const wbemCimtypeUint64&nbsp;&nbsp;&nbsp;&nbsp; = 21&nbsp; ‘Unsigned 64-bit integer
Const wbemCimtypeDatetime&nbsp;&nbsp; = 101 ‘Date/time value
Const wbemCimtypeReference&nbsp; = 102 ‘Reference to a CIM object
Const wbemCimtypeChar16&nbsp;&nbsp;&nbsp;&nbsp; = 103 ’16-bit character


Const ErrAction_None = 0
Const ErrAction_Trace = 1
Const ErrAction_ThrowError = 16
Const ErrAction_Abort = 32
Const ErrAction_ThrowErrorAndAbort = 48


Function GetWMIProperty(oWmi, sPropName, nCIMType, ErrAction)
&nbsp;Dim sValue, oWmiProp


&nbsp;If Not IsObject(oWmi) Then
&nbsp;&nbsp;If (ErrAction And ErrAction_ThrowError) = ErrAction_ThrowError Then _
&nbsp;&nbsp;&nbsp;ThrowScriptErrorNoAbort “Accessing property on invalid WMI object.”, Err


&nbsp;&nbsp;If (ErrAction And ErrAction_Abort) = ErrAction_Abort Then _
&nbsp;&nbsp;&nbsp;ScriptContext.Quit()


&nbsp;&nbsp;GetWMIProperty = “”
&nbsp;&nbsp;Exit Function
&nbsp;End If


&nbsp;On Error Resume Next
&nbsp;Set oWmiProp = oWmi.Properties_.Item(sPropName)
&nbsp;If Err.Number <> 0 Then
&nbsp;&nbsp;If (ErrAction And ErrAction_ThrowError) = ErrAction_ThrowError Then _
&nbsp;&nbsp;&nbsp;ThrowScriptErrorNoAbort “An error occurred while accessing WMI property: ‘” & sPropName & “‘.”, Err


&nbsp;&nbsp;If (ErrAction And ErrAction_Abort) = ErrAction_Abort Then _
&nbsp;&nbsp;&nbsp;ScriptContext.Quit()
&nbsp;End If
&nbsp;On Error Goto 0
&nbsp;
&nbsp;If IsValidObject(oWmiProp) Then
&nbsp;&nbsp;sValue = oWmiProp.Value


&nbsp;&nbsp;If IsNull(sValue) Then
&nbsp;&nbsp;&nbsp;’
&nbsp;&nbsp;&nbsp;’ If value is null, return blank to avoid any issues
&nbsp;&nbsp;&nbsp;’
&nbsp;&nbsp;&nbsp;GetWMIProperty = “”


&nbsp;&nbsp;Else


&nbsp;&nbsp;&nbsp;Select Case (oWmiProp.CIMType)
&nbsp;&nbsp;&nbsp;&nbsp;Case wbemCimtypeString, wbemCimtypeSint16, wbemCimtypeSint32, wbemCimtypeReal32, wbemCimtypeReal64, wbemCimtypeSint8, wbemCimtypeUint8, wbemCimtypeUint16, wbemCimtypeUint32, wbemCimtypeSint64, wbemCimtypeUint64:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetWMIProperty = Trim(CStr(sValue))
&nbsp;&nbsp;&nbsp;&nbsp;Case wbemCimtypeBoolean:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If sValue = 1 Or UCase(sValue) = “TRUE” Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetWMIProperty = “True”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetWMIProperty = “False”
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;Case wbemCimtypeDatetime:


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim sTmpStrDate
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;’
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;’ First attempt to convert the whole wmi date string
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;’
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sTmpStrDate = Mid(sValue, 5, 2) & “/” & _
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mid(sValue, 7, 2) & “/” & _
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Left(sValue, 4) & ” ” & _
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mid (sValue, 9, 2) & “:” & _
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mid(sValue, 11, 2) & “:” & _
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mid(sValue, 13, 2)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If IsDate(sTmpStrDate) Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetWMIProperty = CDate(sTmpStrDate)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Else


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;’
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;’ Second, attempt just to convert the YYYYMMDD
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;’
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sTmpStrDate = Mid(sValue, 5, 2) & “/” & _
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mid(sValue, 7, 2) & “/” & _
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Left(sValue, 4)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If IsDate(sTmpStrDate) Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetWMIProperty = CDate(sTmpStrDate)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;’
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;’ Nothing works – return passed in string
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;’
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetWMIProperty = sValue
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If
&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;Case Else:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetWMIProperty = “”
&nbsp;&nbsp;&nbsp;End Select
&nbsp;&nbsp;End If
&nbsp;Else


&nbsp;&nbsp;If (ErrAction And ErrAction_ThrowError) = ErrAction_ThrowError Then _
&nbsp;&nbsp;&nbsp;ThrowScriptErrorNoAbort “An error occurred while accessing WMI property: ‘” & sPropName & “‘.”, Err


&nbsp;&nbsp;If (ErrAction And ErrAction_Abort) = ErrAction_Abort Then _
&nbsp;&nbsp;&nbsp;ScriptContext.Quit()


&nbsp;&nbsp;GetWMIProperty = “”


&nbsp;End If



&nbsp;If (ErrAction And ErrAction_Trace) = ErrAction_Trace Then _
&nbsp;&nbsp;ScriptContext.Echo “&nbsp; + ” & sPropName & ” :: ‘” & GetWMIProperty & “‘”
&nbsp;
End Function


&nbsp;



Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4
Const EVENT_TYPE_AUDITSUCCESS = 8
Const EVENT_TYPE_AUDITFAILURE = 16



Function ThrowScriptError(sMessage, oErr)

‘ ThrowScriptError :: Creates an event and sends it back to the mom server


&nbsp;&nbsp;&nbsp; On Error Resume Next
&nbsp;&nbsp;&nbsp; ThrowScriptErrorNoAbort sMessage, oErr
&nbsp;ScriptContext.Quit()
End Function


Function ThrowScriptErrorNoAbort(sMessage, oErr)

‘ ThrowScriptError :: Creates an event and sends it back to the mom server


&nbsp;Dim sErrDescription, sErrNumber
&nbsp;sErrDescription = oErr.Description
&nbsp;sErrNumber = oErr.Number


&nbsp;On Error Resume Next


&nbsp;Dim oScriptErrorEvent


&nbsp;Set oScriptErrorEvent = ScriptContext.CreateEvent()
&nbsp;With oScriptErrorEvent
&nbsp;&nbsp;.EventNumber = 40000
&nbsp;&nbsp;.EventType = EVENT_TYPE_ERROR
&nbsp;&nbsp;.Message = sMessage
&nbsp;&nbsp;.SetEventParameter “Microsoft SQL Server”
&nbsp;&nbsp;.SetEventParameter sMessage
&nbsp;&nbsp;.SetEventParameter sErrDescription
&nbsp;&nbsp;.SetEventParameter sErrNumber
&nbsp;End With
&nbsp;ScriptContext.Submit oScriptErrorEvent
&nbsp;ScriptContext.Echo “ThrowScriptError(‘” & sMessage & “‘)”
End Function



Function MomCreateObject(sProgramId)

‘ MomCreateObject :: Creates an automation object.


&nbsp;On Error Resume Next
&nbsp;Set MomCreateObject = CreateObject(sProgramId)
&nbsp;If Err.Number <> 0 Then
&nbsp;&nbsp;ThrowScriptError “Unable to create automation object ‘” & sProgramId & “‘”, Err
&nbsp;End If
&nbsp;On Error Goto 0
End Function








Michel


&nbsp;&nbsp;