<WriteActionModuleType ID="SMSv4_Service_Discovery___Server" Accessibility="Internal" Comment="{C5A1AB22-2DE2-47C4-896E-12BCFC3D069F}">
<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 Service Discovery - Server
'
' Purpose - Performs service discovery functions on ConfigMgr 2007 Servers.
'
' Assumptions - This script will only run on ConfigMgr 2007 Servers.
'
' Parameters - None
'
' Change Hist - Date Version Description
' -------- --------------- -----------
' 02/15/04 02.50.0161.0000 Created
' 04/08/04 02.50.0174.0000 Update for new state monitoring
' component support.
' 05/08/04 02.50.0178.0000 Added topology diagram shape
' annotations. Replaced AttributeValue_
' MicrosoftSMS2003SQLMonitorService with
' AttributeValue_MicrosoftSMSv4SQLServer
' and updated computer group formula for
' Microsoft SMS 2003 Site Database Servers.
' 06/02/04 05.0.2702.0000 Added Reporting Points and Server
' Locator Points to method
' InComputerGroup_MicrosoftSMS2003Servers.
' Removed version check from method
' InComputerGroup_
' MicrosoftSMS2003DistributionPointServers.
' 04/23/05 05.0.2754.0000 Updated for SMSv4.
' 01/06/06 05.0.2809.0000 Change computer attribute and group
' functions to use Operations Management
' registry information.
' 04/08/06 05.0.2902.0000 Updated for SMP and PSP.
' 08/03/06 05.0.2905.0000 Updated for SUP.
' 07/29/07 05.0.2906.0000 Removed Sender discovery and added FSP.
' 08/18/07 6.0.5000.2 Added event tracing support.
' 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.
'
' (c) Copyright 2007, Microsoft Corp., All Rights Reserved
'*******************************************************************************
'Event and Log Messages Constants
'================================
'Start Localization
Const WMI_NO_NAMESPACE_SOURCE = "Unable to open WMI Namespace {Namespace}"
Const WMI_NO_NAMESPACE_DESCRIPTION = "Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists. Error:{ErrorNumber}, {ErrorDescription}."
Const WMI_NO_INSTANCES_SOURCE = "The class name '{ClassName}' returned no instances."
Const WMI_NO_INSTANCES_DESCRIPTION = "Please check to see if this is a valid WMI class name. Error:{ErrorNumber}, {ErrorDescription}."
Const WMI_NO_VALID_INSTANCES_SOURCE = "The class name '{ClassName}' did not return any valid instances."
Const WMI_NO_VALID_INSTANCES_DESCRIPTION = "Please check to see if this is a valid WMI class name. Error:{ErrorNumber}, {ErrorDescription}."
Const WMI_QUERY_NO_RESULTS_SOURCE = "The Query '{Query}' returned an invalid result set."
Const WMI_QUERY_NO_RESULTS_DESCRIPTION = "Please check to see if this is a valid WMI Query. Error:{ErrorNumber}, {ErrorDescription}."
Const WMI_QUERY_NO_VALID_INSTANCES_SOURCE = "The Query '{Query}' did not return any valid instances."
Const WMI_QUERY_NO_VALID_INSTANCES_DESCRIPTION = "Please check to see if this is a valid WMI Query. Error:{ErrorNumber}, {ErrorDescription}."
'End Localization
'Discovery Constants
'===================
Const DISCOVERY_SCOPE_ID = "{BCD40058-E0D9-4E54-BD4D-510D30CD2918}" 'Rule GUID or the PR that runs this script
Const SCRIPT_NAME = "ConfigMgr 2007 Service Discovery - Server"
' Global variables
'=================
Dim g_oUtil ' Utility class for MOM events, logging and registry access.
'******************************************************************************
' Replacement string functions for event and log messages
'
'
Function GET_WMI_NO_NAMESPACE_SOURCE(ByVal sNamespace)
GET_WMI_NO_NAMESPACE_SOURCE = Replace(WMI_NO_NAMESPACE_SOURCE, "{Namespace}", sNamespace)
End Function
Function GET_WMI_NO_NAMESPACE_DESCRIPTION(ByVal lErrorNumber, ByVal sErrorDescription)
Dim sResult
sResult = Replace(WMI_NO_NAMESPACE_DESCRIPTION, "{ErrorNumber}", lErrorNumber)
GET_WMI_NO_NAMESPACE_DESCRIPTION = Replace(sResult, "{ErrorDescription}", sErrorDescription)
End Function
Function GET_WMI_NO_INSTANCES_SOURCE(ByVal sClassName)
GET_WMI_NO_INSTANCES_SOURCE = Replace(WMI_NO_INSTANCES_SOURCE, "{ClassName}", sClassName)
End Function
Function GET_WMI_NO_INSTANCES_DESCRIPTION(ByVal lErrorNumber, ByVal sErrorDescription)
Dim sResult
sResult = Replace(WMI_NO_INSTANCES_DESCRIPTION, "{ErrorNumber}", lErrorNumber)
GET_WMI_NO_INSTANCES_DESCRIPTION = Replace(sResult, "{ErrorDescription}", sErrorDescription)
End Function
Function GET_WMI_NO_VALID_INSTANCES_SOURCE(ByVal sClassName)
GET_WMI_NO_VALID_INSTANCES_SOURCE = Replace(WMI_NO_VALID_INSTANCES_SOURCE, "{ClassName}", sClassName)
End Function
Function GET_WMI_NO_VALID_INSTANCES_DESCRIPTION(ByVal lErrorNumber, ByVal sErrorDescription)
Dim sResult
sResult = Replace(WMI_NO_VALID_INSTANCES_DESCRIPTION, "{ErrorNumber}", lErrorNumber)
GET_WMI_NO_VALID_INSTANCES_DESCRIPTION = Replace(sResult, "{ErrorDescription}", sErrorDescription)
End Function
Function GET_WMI_QUERY_NO_RESULTS_SOURCE(ByVal sQuery)
GET_WMI_QUERY_NO_RESULTS_SOURCE = Replace(WMI_QUERY_NO_RESULTS_SOURCE, "{Query}", sQuery)
End Function
Function GET_WMI_QUERY_NO_RESULTS_DESCRIPTION(ByVal lErrorNumber, ByVal sErrorDescription)
Dim sResult
sResult = Replace(WMI_QUERY_NO_RESULTS_DESCRIPTION, "{ErrorNumber}", lErrorNumber)
GET_WMI_QUERY_NO_RESULTS_DESCRIPTION = Replace(sResult, "{ErrorDescription}", sErrorDescription)
End Function
Function GET_WMI_QUERY_NO_VALID_INSTANCES_DESCRIPTION(ByVal lErrorNumber, ByVal sErrorDescription)
Dim sResult
sResult = Replace(WMI_QUERY_NO_VALID_INSTANCES_DESCRIPTION, "{ErrorNumber}", lErrorNumber)
GET_WMI_QUERY_NO_VALID_INSTANCES_DESCRIPTION = Replace(sResult, "{ErrorDescription}", sErrorDescription)
End Function
Function GET_WMI_QUERY_NO_VALID_INSTANCES_SOURCE(ByVal sQuery)
GET_WMI_QUERY_NO_VALID_INSTANCES_SOURCE = Replace(WMI_QUERY_NO_VALID_INSTANCES_SOURCE, "{Query}", sQuery)
End Function
'******************************************************************************
' Name: Main
'
' Purpose: Entry point for program execution.
'
' Parameters: None
'
' Returns: Nothing
'
' Remarks: This routine will manage its error return.
'
Sub Main()
Dim bEventTracing
On Error Resume Next
'Initialize utility object and begin tracing.
'============================================
Set g_oUtil = new Util
Call g_oUtil.SetDebugLevel(g_oUtil.DBG_TRACE)
Call g_oUtil.LogMessage(g_oUtil.DBG_TRACE, " " + SCRIPT_NAME + " script starting at local time: " + 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: " & CStr(Time)
End If
'WMI is used by discovery functions in this script so check that it is
'accessible.
'=====================================================================
If True <> IsWMIAccessible() Then
Set g_oUtil = Nothing
Exit Sub
End if
'Perform service discovery.
'==========================
DoServiceDiscovery
If (bEventTracing = True) Then
LogEvent EVENT_ID_SCRIPTSUCCESS, EVENT_TYPE_INFORMATION, "completed at local time: " & CStr(Time)
End If
Call g_oUtil.LogMessage(g_oUtil.DBG_TRACE, " " + SCRIPT_NAME + " script completed at local time: " + CStr(Time))
Set g_oUtil = Nothing
End Sub
'******************************************************************************
' Name: IsWMIAccessible
'
' Purpose: To determine whether the WMI service is running and accessible
'
' Parameters: None
'
' Returns: Boolean, returns True if the WMI service and root\default namespace
' is accessible.
'
' Remarks: If an error is encountered this function will throw an exception
' the caller MUST handle this.
'
Function IsWMIAccessible()
Dim objService
On Error Resume Next
Err.Clear
Set objService = GetObject("winmgmts:\\" + ScriptContext.TargetComputer + "\root\default")
If Err Then
IsWMIAccessible = False
Call g_oUtil.LogMessage(g_oUtil.DBG_TRACE, "WMI Access Failure, Error #: " + CStr(Err.Number) + ", Description: " + Err.Description)
Else
IsWMIAccessible = True
End If
End Function
'******************************************************************************
' Name: DoServiceDiscovery
'
' Purpose: Performs all discovery service functions.
'
' Parameters: None
'
' Returns: Nothing
'
' Remarks: This routine will manage its error return.
'
Sub DoServiceDiscovery
Dim oDiscData
'Create Discovery Data object.
'=============================
Set oDiscData = ScriptContext.CreateDiscoveryData()
oDiscData.ScopeID = DISCOVERY_SCOPE_ID
'Initialize Discovery Data object for the SMS class.
'===================================================
Initialize oDiscData
'Submit the Discovery Data object.
'=================================
Call g_oUtil.LogMessage(g_oUtil.DBG_TRACE, "Submitting Discovery data packet.")
ScriptContext.Submit oDiscData
End Sub
'******************************************************************************
' Name: Initialize
'
' Purpose: Initializes Discovery Data object for appropriate SMS class(es).
'
' Parameters: ByVal oDiscData Discovery Data oject returned by
' ScriptContext.CreateDiscoveryData().
'
' Returns: Nothing
'
' Remarks: This routine will manage its error return.
'
Sub Initialize(ByVal oDiscData)
Dim oSMSServer
Dim oCollection
Dim oInstance
Dim strSMSComponents
'Initialize SMSServer object for accessing SMS Server data.
'==========================================================
Set oSMSServer = new SMSServer
'Specify the discovery scope for class components (subgroups or functions)
'and properties of the class.
'=========================================================================
'Create and initialize instances of the class based on components and
'and properties present.
'====================================================================
Set oInstance = oCollection.CreateInstance()
If oSMSServer.InComputerGroup_MicrosoftSMSv4SiteDatabaseServers() Then
If IsEmpty(strSMSComponents) Then
strSMSComponents = SMS_SERVER_SITE_DATABASE_COMPONENT_ID
Else
strSMSComponents = strSMSComponents & ", " & SMS_SERVER_SITE_DATABASE_COMPONENT_ID
End If
End If
If oSMSServer.InComputerGroup_MicrosoftSMSv4DistributionPointServers() Then
If IsEmpty(strSMSComponents) Then
strSMSComponents = SMS_SERVER_DISTRIBUTION_POINT_COMPONENT_ID
Else
strSMSComponents = strSMSComponents & ", " & SMS_SERVER_DISTRIBUTION_POINT_COMPONENT_ID
End If
End If
If oSMSServer.InComputerGroup_MicrosoftSMSv4FallbackStatusPointServers() Then
If IsEmpty(strSMSComponents) Then
strSMSComponents = SMS_SERVER_FALLBACK_STATUS_POINT_COMPONENT_ID
Else
strSMSComponents = strSMSComponents & ", " & SMS_SERVER_FALLBACK_STATUS_POINT_COMPONENT_ID
End If
End If
If oSMSServer.InComputerGroup_MicrosoftSMSv4ManagementPointServers() Then
If IsEmpty(strSMSComponents) Then
strSMSComponents = SMS_SERVER_MANAGEMENT_POINT_COMPONENT_ID
Else
strSMSComponents = strSMSComponents & ", " & SMS_SERVER_MANAGEMENT_POINT_COMPONENT_ID
End If
End If
If oSMSServer.InComputerGroup_MicrosoftSMSv4Providers() Then
If IsEmpty(strSMSComponents) Then
strSMSComponents = SMS_SERVER_PROVIDER_COMPONENT_ID
Else
strSMSComponents = strSMSComponents & ", " & SMS_SERVER_PROVIDER_COMPONENT_ID
End If
End If
If oSMSServer.InComputerGroup_MicrosoftSMSv4PXEServicePointServers() Then
If IsEmpty(strSMSComponents) Then
strSMSComponents = SMS_SERVER_PXE_SERVICE_POINT_COMPONENT_ID
Else
strSMSComponents = strSMSComponents & ", " & SMS_SERVER_PXE_SERVICE_POINT_COMPONENT_ID
End If
End If
If oSMSServer.InComputerGroup_MicrosoftSMSv4ReportingPointServers() Then
If IsEmpty(strSMSComponents) Then
strSMSComponents = SMS_SERVER_REPORTING_POINT_COMPONENT_ID
Else
strSMSComponents = strSMSComponents & ", " & SMS_SERVER_REPORTING_POINT_COMPONENT_ID
End If
End If
If oSMSServer.InComputerGroup_MicrosoftSMSv4SystemHealthValidatorServers() Then
If IsEmpty(strSMSComponents) Then
strSMSComponents = SMS_SERVER_SYSTEM_HEALTH_VALIDATOR_COMPONENT_ID
Else
strSMSComponents = strSMSComponents & ", " & SMS_SERVER_SYSTEM_HEALTH_VALIDATOR_COMPONENT_ID
End If
End If
If oSMSServer.InComputerGroup_MicrosoftSMSv4ServerLocatorPointServers() Then
If IsEmpty(strSMSComponents) Then
strSMSComponents = SMS_SERVER_SERVER_LOCATOR_POINT_COMPONENT_ID
Else
strSMSComponents = strSMSComponents & ", " & SMS_SERVER_SERVER_LOCATOR_POINT_COMPONENT_ID
End If
End If
If oSMSServer.InComputerGroup_MicrosoftSMSv4StateMigrationPointServers() Then
If IsEmpty(strSMSComponents) Then
strSMSComponents = SMS_SERVER_STATE_MIGRATION_POINT_COMPONENT_ID
Else
strSMSComponents = strSMSComponents & ", " & SMS_SERVER_STATE_MIGRATION_POINT_COMPONENT_ID
End If
End If
If oSMSServer.InComputerGroup_MicrosoftSMSv4SiteServers() Then
If IsEmpty(strSMSComponents) Then
strSMSComponents = SMS_SERVER_SITE_SERVER_COMPONENT_ID
Else
strSMSComponents = strSMSComponents & ", " & SMS_SERVER_SITE_SERVER_COMPONENT_ID
End If
End If
If oSMSServer.InComputerGroup_MicrosoftSMSv4SoftwareUpdatePointServers() Then
If IsEmpty(strSMSComponents) Then
strSMSComponents = SMS_SERVER_SOFTWARE_UPDATE_POINT_COMPONENT_ID
Else
strSMSComponents = strSMSComponents & ", " & SMS_SERVER_SOFTWARE_UPDATE_POINT_COMPONENT_ID
End If
If oSMSServer.InComputerGroup_MicrosoftSMSv4CentralSiteServers() Then
oInstance.AddProperty SMS_SERVER_SHAPE_ANNOTATION_1_ATTRIBUTE_ID, SMS_SERVER_SHAPE_ANNOTATION_1_CENTRAL_SITE
ElseIf oSMSServer.InComputerGroup_MicrosoftSMSv4PrimarySiteServers() Then
oInstance.AddProperty SMS_SERVER_SHAPE_ANNOTATION_1_ATTRIBUTE_ID, SMS_SERVER_SHAPE_ANNOTATION_1_PRIMARY_SITE
ElseIf oSMSServer.InComputerGroup_MicrosoftSMSv4SecondarySiteServers() Then
oInstance.AddProperty SMS_SERVER_SHAPE_ANNOTATION_1_ATTRIBUTE_ID, SMS_SERVER_SHAPE_ANNOTATION_1_SECONDARY_SITE
ElseIf oSMSServer.InComputerGroup_MicrosoftSMSv4DistributionPointServers() Or _
oSMSServer.InComputerGroup_MicrosoftSMSv4FallbackStatusPointServers() Or _
oSMSServer.InComputerGroup_MicrosoftSMSv4PXEServicePointServers() Or _
oSMSServer.InComputerGroup_MicrosoftSMSv4ReportingPointServers() Or _
oSMSServer.InComputerGroup_MicrosoftSMSv4SystemHealthValidatorServers() Or _
oSMSServer.InComputerGroup_MicrosoftSMSv4ServerLocatorPointServers() Or _
oSMSServer.InComputerGroup_MicrosoftSMSv4StateMigrationPointServers() Or _
oSMSServer.InComputerGroup_MicrosoftSMSv4SoftwareUpdatePointServers() Then
oInstance.AddProperty SMS_SERVER_SHAPE_ANNOTATION_1_ATTRIBUTE_ID, SMS_SERVER_SHAPE_ANNOTATION_1_SITE_SYSTEM
End If
If oSMSServer.InComputerGroup_MicrosoftSMSv4ManagementPointServers() Then
oInstance.AddProperty SMS_SERVER_SHAPE_ANNOTATION_2_ATTRIBUTE_ID, SMS_SERVER_SHAPE_ANNOTATION_2_MANAGEMENT_POINT
End If
If oSMSServer.InComputerGroup_MicrosoftSMSv4SiteDatabaseServers() Then
oInstance.AddProperty SMS_SERVER_SHAPE_ANNOTATION_3_ATTRIBUTE_ID, SMS_SERVER_SHAPE_ANNOTATION_3_SITE_DATABASE
End If
'==========================================================================
' Class: SMSServer
' Description: Provides key property information about an SMS Server.
'==========================================================================
Class SMSServer
'---------------
' Properties and Constants (Initialized on constructor due to VBS behavior)
'---------------
Public SMSv4_MIN_VERSION
'---------------
' Methods
'---------------
'=============
' Method: Class_Initialize
' Description: This is the constructor
' Parameters:
'=============
Private Sub Class_Initialize()
SMSv4_MIN_VERSION = "4.00.0000.0000"
End Sub
'=============
' Method: Class_Terminate
' Description: This is the destructor
' Parameters:
'=============
Private Sub Class_Terminate()
End Sub
'=============
' Method: GetSMSVersion
'
' Description: Get the SMS Version from the registry.
'
' Parameters: None
'
' Returns: A string if successful otherwise empty.
'=============
Public Function GetSMSVersion()
'=============
' Method: GetSMSSiteCode
'
' Description: Get the SMS Site Code from the registry.
'
' Parameters: None
'
' Returns: A string if successful otherwise empty.
'=============
Public Function GetSMSSiteCode()
'=============
' Method: InComputerGroup_MicrosoftSMSv4CentralSiteServers
'
' Description: "Microsoft ConfigMgr 2007 Central Site Servers" computer
' group. ConfigMgr 2007 site servers that are central site
' servers.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4CentralSiteServers()
If AttributeValue_MicrosoftSMSv4CentralSiteServer() = 1 And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4CentralSiteServers = True
Else
InComputerGroup_MicrosoftSMSv4CentralSiteServers = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4ComponentServersbasedonSMSExecutive
'
' Description: "Microsoft ConfigMgr 2007 Component Servers based on
' SMS Executive" computer group. ConfigMgr 2007 site servers
' or site systems running the SMS Executive service.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4ComponentServersbasedonSMSExecutive()
If AttributeValue_MicrosoftSMSv4ExecutiveService() And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4ComponentServersbasedonSMSExecutive = True
Else
InComputerGroup_MicrosoftSMSv4ComponentServersbasedonSMSExecutive = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4DeviceManagementPointServers
'
' Description: "Microsoft ConfigMgr 2007 Device Management Point Servers"
' computer group. ConfigMgr 2007 site servers or site systems
' that are Device Management Points.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4DeviceManagementPointServers()
If InComputerGroup_MicrosoftSMSv4ManagementPointServers() And _
AttributeValue_MicrosoftSMSv4ManagementPointDeviceManager() Then
InComputerGroup_MicrosoftSMSv4DeviceManagementPointServers = True
Else
InComputerGroup_MicrosoftSMSv4DeviceManagementPointServers = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4DistributionPointServers
'
' Description: "Microsoft ConfigMgr 2007 Distribution Point Servers"
' computer group. ConfigMgr 2007 site server or site systems
' that are Distribution Point servers.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4DistributionPointServers()
If AttributeValue_MicrosoftSMSv4DistributionPoint() And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4DistributionPointServers = True
Else
InComputerGroup_MicrosoftSMSv4DistributionPointServers = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4FallbackStatusPointServers
'
' Description: "Microsoft ConfigMgr 2007 Fallback Status Point Servers" computer group.
' ConfigMgr 2007 site servers or site systems that are Fallback Status
' Points.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4FallbackStatusPointServers()
If AttributeValue_MicrosoftSMSv4FallbackStatusPoint() And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4FallbackStatusPointServers = True
Else
InComputerGroup_MicrosoftSMSv4FallbackStatusPointServers = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4ManagementPointServers
'
' Description: "Microsoft ConfigMgr 2007 Management Point Servers" computer
' group. ConfigMgr 2007 site servers or site systems that are
' Management Points.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4ManagementPointServers()
If AttributeValue_MicrosoftSMSv4ManagementPoint() And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4ManagementPointServers = True
Else
InComputerGroup_MicrosoftSMSv4ManagementPointServers = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4PrimarySiteServers
'
' Description: "Microsoft ConfigMgr 2007 Primary Site Servers" computer
' group. ConfigMgr 2007 site servers that are primary site
' servers.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4PrimarySiteServers()
If AttributeValue_MicrosoftSMSv4SiteServerSiteType() = 1 And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4PrimarySiteServers = True
Else
InComputerGroup_MicrosoftSMSv4PrimarySiteServers = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4Providers
'
' Description: "Microsoft ConfigMgr 2007 Providers" computer group.
' ConfigMgr 2007 site servers or site database servers that
' are SMS Providers.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4Providers()
If AttributeValue_MicrosoftSMSv4Provider() And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4Providers = True
Else
InComputerGroup_MicrosoftSMSv4Providers = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4PXEServicePointServers
'
' Description: "Microsoft ConfigMgr 2007 PXE Service Point Servers" computer
' group. ConfigMgr 2007 site servers or site systems that are
' PXE Service Points.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4PXEServicePointServers()
If AttributeValue_MicrosoftSMSv4PXEServicePoint() And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4PXEServicePointServers = True
Else
InComputerGroup_MicrosoftSMSv4PXEServicePointServers = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4ReportingPointServers
'
' Description: "Microsoft ConfigMgr 2007 Reporting Point Servers" computer
' group. ConfigMgr 2007 site server or site systems that are
' Reporting Points.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4ReportingPointServers()
If AttributeValue_MicrosoftSMSv4ReportingPoint() And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4ReportingPointServers = True
Else
InComputerGroup_MicrosoftSMSv4ReportingPointServers = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4SecondarySiteServers
'
' Description: "Microsoft ConfigMgr 2007 Secondary Site Servers" computer
' group. ConfigMgr 2007 site servers that are secondary site
' servers.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4SecondarySiteServers()
If AttributeValue_MicrosoftSMSv4SiteServerSiteType() = 2 And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4SecondarySiteServers = True
Else
InComputerGroup_MicrosoftSMSv4SecondarySiteServers = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4ServerLocatorPointServers
'
' Description: "Microsoft ConfigMgr 2007 Server Locator Point Servers" computer
' group. ConfigMgr 2007 site server or site systems that are
' Reporting Points.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4ServerLocatorPointServers()
If AttributeValue_MicrosoftSMSv4ServerLocatorPoint() And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4ServerLocatorPointServers = True
Else
InComputerGroup_MicrosoftSMSv4ServerLocatorPointServers = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4SiteDatabaseServers
'
' Description: "Microsoft ConfigMgr 2007 Site Database Servers" computer
' group. ConfigMgr 2007 site server or site systems that are
' Site Database Servers.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4SiteDatabaseServers()
If AttributeValue_MicrosoftSMSv4SQLServer() And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4SiteDatabaseServers = True
Else
InComputerGroup_MicrosoftSMSv4SiteDatabaseServers = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4StateMigrationPointServers
'
' Description: "Microsoft ConfigMgr 2007 State Migration Point Servers" computer
' group. ConfigMgr 2007 site server or site systems that are
' State Migration Point Servers.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4StateMigrationPointServers()
If AttributeValue_MicrosoftSMSv4StateMigrationPoint() And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4StateMigrationPointServers = True
Else
InComputerGroup_MicrosoftSMSv4StateMigrationPointServers = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4SystemHealthValidatorServers
'
' Description: "Microsoft ConfigMgr 2007 System Health Validator Servers" computer
' group. ConfigMgr 2007 site server or site systems that are
' running IAS and hosting the SMS System Health Validator.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4SystemHealthValidatorServers()
If AttributeValue_MicrosoftSMSv4SystemHealthValidator() And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4SystemHealthValidatorServers = True
Else
InComputerGroup_MicrosoftSMSv4SystemHealthValidatorServers = False
End If
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4ComponentServersbasedonIIS
'
' Description: "Microsoft ConfigMgr 2007 Component Servers based on IIS"
' computer group. ConfigMgr 2007 site servers or site systems
' running IIS services.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4ComponentServersbasedonIIS()
InComputerGroup_MicrosoftSMSv4ComponentServersbasedonIIS = _
InComputerGroup_MicrosoftSMSv4ManagementPointServers() Or _
InComputerGroup_MicrosoftSMSv4ReportingPointServers() Or _
InComputerGroup_MicrosoftSMSv4ServerLocatorPointServers()
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4Servers
'
' Description: "Microsoft ConfigMgr 2007 Servers" computer group.
' All qualifying (see group name) servers in the
' hierarchy (not just the site).
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4Servers()
InComputerGroup_MicrosoftSMSv4Servers = _
InComputerGroup_MicrosoftSMSv4ComponentServersbasedonSMSExecutive() Or _
InComputerGroup_MicrosoftSMSv4SiteDatabaseServers() Or _
InComputerGroup_MicrosoftSMSv4Providers() Or _
InComputerGroup_MicrosoftSMSv4DistributionPointServers() Or _
InComputerGroup_MicrosoftSMSv4ReportingPointServers() Or _
InComputerGroup_MicrosoftSMSv4ServerLocatorPointServers()
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4SiteServers
'
' Description: "Microsoft ConfigMgr 2007 Site Servers" computer group.
' ConfigMgr 2007 site servers that are primary or secondary
' site servers.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4SiteServers()
InComputerGroup_MicrosoftSMSv4SiteServers = _
InComputerGroup_MicrosoftSMSv4PrimarySiteServers() Or _
InComputerGroup_MicrosoftSMSv4SecondarySiteServers()
End Function
'=============
' Method: InComputerGroup_MicrosoftSMSv4SoftwareUpdatePointServers
'
' Description: "Microsoft ConfigMgr 2007 Software Update Point Servers" computer
' group. ConfigMgr 2007 site server or site systems that are
' Software Update Point Servers.
'
' Parameters: None
'
' Returns: True if this server is in the computer group else false.
'=============
Public Function InComputerGroup_MicrosoftSMSv4SoftwareUpdatePointServers()
If AttributeValue_MicrosoftSMSv4SoftwareUpdatePoint() And _
AttributeValue_MicrosoftSMSv4HighestVersionNumber() > SMSv4_MIN_VERSION Then
InComputerGroup_MicrosoftSMSv4SoftwareUpdatePointServers = True
Else
InComputerGroup_MicrosoftSMSv4SoftwareUpdatePointServers = False
End If
End Function
'=============
' Method: AttributeValue_MicrosoftSMSv4AgentHostService
'
' Description: "Microsoft ConfigMgr 2007 Agent Host Service" computer
' attribute. Checks for installation of SMS Agent Host
' service.
'
' Parameters: None
'
' Returns: True if registry key string value
' SYSTEM\CurrentControlSet\Services\CcmExec\DisplayName
' exists.
'=============
Public Function AttributeValue_MicrosoftSMSv4AgentHostService()
'=============
' Method: AttributeValue_MicrosoftSMSv4DistributionPoint
'
' Description: "Microsoft ConfigMgr 2007 Distribution Point" computer
' attribute. Checks for installation of SMS Distribution
' Point.
'
' Parameters: None
'
' Returns: True if registry key SOFTWARE\Microsoft\SMS\Operations
' Management\SMS Server Role\SMS Distribution Point exists.
'=============
Public Function AttributeValue_MicrosoftSMSv4DistributionPoint()
'=============
' Method: AttributeValue_MicrosoftSMSv4FallbackStatusPoint
'
' Description: "Microsoft ConfigMgr 2007 Fallback Status Point" computer attribute.
' Checks for the installation of SMS Fallback Status Point.
'
' Parameters: None
'
' Returns: True if registry key SOFTWARE\Microsoft\SMS\
' Operations Management\SMS Server Role\
' SMS Fallback Status Point exists.
'=============
Public Function AttributeValue_MicrosoftSMSv4FallbackStatusPoint()
'=============
' Method: AttributeValue_MicrosoftSMSv4HighestVersionNumber
'
' Description: "Microsoft ConfigMgr 2007 Highest Version Number" computer
' attribute. A string containing the Operations Management
' version number for an SMS Server, the highest SMS Server
' component version.
'
' Parameters: None
'
' Returns: Registry key string value SOFTWARE\Microsoft\SMS\
' Operations Management\Version
'=============
Public Function AttributeValue_MicrosoftSMSv4HighestVersionNumber()
'=============
' Method: AttributeValue_MicrosoftSMSv4CentralSiteServer
'
' Description: "Microsoft ConfigMgr 2007 Central Site Server" computer
' attribute. A DWORD value indicating if an SMS Site
' Server is a Central Site Server.
'
' Parameters: None
'
' Returns: Registry key DWORD value SOFTWARE\Microsoft\SMS\
' Operations Management\SMS Server Role\SMS Site Server\
' Central Site
'=============
Public Function AttributeValue_MicrosoftSMSv4CentralSiteServer()
'=============
' Method: AttributeValue_MicrosoftSMSv4ParentSiteCode
'
' Description: "Microsoft ConfigMgr 2007 Parent Site Code" computer
' attribute. A string containing the parent site code
' for an SMS Site Server. This value is empty on a
' Central Site Server.
'
' Parameters: None
'
' Returns: Registry key string value SOFTWARE\Microsoft\SMS\
' Identification\Parent Site Code
'=============
Public Function AttributeValue_MicrosoftSMSv4ParentSiteCode()
'=============
' Method: AttributeValue_MicrosoftSMSv4SiteCode
'
' Description: "Microsoft ConfigMgr 2007 Site Code" computer attribute.
' A string containing the site code for an SMS Site
' Server.
'
' Parameters: None
'
' Returns: Registry key string value SOFTWARE\Microsoft\SMS\
' Operations Management\Site Code
'=============
Public Function AttributeValue_MicrosoftSMSv4SiteCode()
'=============
' Method: AttributeValue_MicrosoftSMSv4SiteServerType
'
' Description: "Microsoft ConfigMgr 2007 Site Server Type" computer
' attribute. A DWORD value indicating the type of
' SMS Site Server or Administrator Console.
'
' Parameters: None
'
' Returns: Registry key DWORD value SOFTWARE\Microsoft\SMS\
' Setup\Type
'=============
Public Function AttributeValue_MicrosoftSMSv4SiteServerType()
'=============
' Method: AttributeValue_MicrosoftSMSv4SiteServerSiteType
'
' Description: "Microsoft ConfigMgr 2007 Site Server Site Type" computer
' attribute. A DWORD value indicating the type of
' SMS Site Server.
'
' Parameters: None
'
' Returns: Registry key DWORD value SOFTWARE\Microsoft\SMS\
' Operations Management\SMS Server Role\SMS Site Server\
' Site Type
'=============
Public Function AttributeValue_MicrosoftSMSv4SiteServerSiteType()
'=============
' Method: AttributeValue_MicrosoftSMSv4SystemHealthValidator
'
' Description: "Microsoft ConfigMgr 2007 System Health Validator" computer attribute.
' Checks for installation of SMS System Health Validator.
'
' Parameters: None
'
' Returns: True if registry key SOFTWARE\Microsoft\SMS\Operations
' Management\SMS Server Role\System Health Validator exists.
'=============
Public Function AttributeValue_MicrosoftSMSv4SystemHealthValidator()
'==========================================================================
' 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_OPMGMT_SMS_SERVER_ROLE
Public REG_PATH_SMS_SERVER_OPMGMT_SMS_SERVER_ROLE_BASE
Public REG_PATH_SMS_SERVER_OPMGMT_COMPONENTS
Public REG_PATH_SMS_SERVER_OPMGMT_COMPONENTS_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_SMS_SERVER_IDENTIFICATION
Public REG_KEY_SMS_SERVER_OPERATIONS_MANAGEMENT
Public REG_KEY_SMS_SERVER_SETUP
Public REG_KEY_SMS_SERVER_OPMGMT_DISTRIBUTION_POINT
Public REG_KEY_SMS_SERVER_OPMGMT_FALLBACK_STATUS_POINT
Public REG_KEY_SMS_SERVER_OPMGMT_MANAGEMENT_POINT
Public REG_KEY_SMS_SERVER_OPMGMT_PXE_SERVICE_POINT
Public REG_KEY_SMS_SERVER_OPMGMT_REPORTING_POINT
Public REG_KEY_SMS_SERVER_OPMGMT_SERVER_LOCATOR_POINT
Public REG_KEY_SMS_SERVER_OPMGMT_SITE_SERVER
Public REG_KEY_SMS_SERVER_OPMGMT_SQL_SERVER
Public REG_KEY_SMS_SERVER_OPMGMT_SOFTWARE_UPDATE_POINT
Public REG_KEY_SMS_SERVER_OPMGMT_STATE_MIGRATION_POINT
Public REG_KEY_SMS_SERVER_OPMGMT_SYSTEM_HEALTH_VALIDATOR
Public REG_KEY_SMS_SERVER_OPMGMT_COMP_SMS_MP_DEVICE_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_SITE_TYPE
'---------------
' Methods
'---------------
'=============
' Method: Class_Initialize
' Description: This is the constructor
' Parameters:
'=============
Private Sub Class_Initialize()
'=============
' 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 <= 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)
'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)
'Read value from registry
if oReg.GetDWORDValue(lHive, strKeyPath, strValueName, lValueData) = 0 Then
Call LogMessage(DBG_TRACE, "Value of Registry Key: " + strKeyPath + "\" + strValueName + " = " & 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)
'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)
'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)
'=============
' 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)
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)
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."
'Check access to the specified registry key
HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\SMS"
KEY_QUERY_VALUE = &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 <> 0 Then
ScriptContext.Echo "Unable to open WMI Namespace " & 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 <> 0 Then
ScriptContext.Echo "Unable to open WMI Namespace " & 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 <> 0 Then
ScriptContext.Echo "The class name '" & sInstance & "' returned no instances. Error:" & nErrNumber & ", " & sErrDescription & "."
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 <> 0 Then
ScriptContext.Echo "The class name '" & sInstance & "' did not return any valid instances. Error:" & nErrNumber & ", " & sErrDescription & "."
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 <> 0 Then
ScriptContext.Echo "Unable to open WMI Namespace " & 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 <> 0 Then
ScriptContext.Echo "The Query '" & sQuery & "' returned an invalid result set. Error:" & nErrNumber & ", " & sErrDescription & "."
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 <> 0 Then
ScriptContext.Echo "The Query '" & sQuery & "' did not return any valid instances. Error:" & nErrNumber & ", " & sErrDescription & "."
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: 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 >= Len(strErr) Then
'If we don't have an error description, then check to see if the
'error is a 0x8007xxxx error. If it is, then look it up.
'===============================================================
Const ErrorMask = &HFFFF0000
Const HiWord8007 = &H80070000
Const LoWordMask = 65535 ' This is equivalent to 0x0000FFFF
If (lErr And ErrorMask) = HiWord8007 Then
'Attempt to use 'net helpmsg' to get a description for the error.
'================================================================
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If Err = 0 Then
Dim oExec
Set oExec = oShell.Exec("net helpmsg " & (lErr And LoWordMask))
Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i < 5)
strErr = strMessage
End If
End If
End If
GetErrorString = vbCrLf & "The error returned was: '" & strErr & "' " & lErr & " (0x" & Hex(lErr) & ")"
End Function
'******************************************************************************
' Name: ScriptError
'
' Purpose: To generate a warning about a runtime script error.
'
' Parameters: strError The description of the error
'
' Returns: Nothing
'
Sub ScriptError(strError)
LogEvent EVENT_ID_SCRIPTERROR, EVENT_TYPE_WARNING, "encountered a runtime error." & vbCrLf & "Failed to " & strError
End Sub
'******************************************************************************
' Name: LogEvent
'
' Purpose: To generate a MOM event
'
' Parameters: lEventID The event code
' lEventType The severity of the event
' strMessage The message to include in the event
'
' Returns: Nothing
'
Sub LogEvent(lEventID, lEventType, strMessage)
Dim oEvent
On Error Resume Next
Set oEvent = ScriptContext.CreateEvent
oEvent.EventNumber = lEventID
oEvent.EventType = lEventType
oEvent.Message = "The script '" & ScriptContext.Name & "' running under processing rule '" & ScriptContext.ProcessingRule.Name & "' " & strMessage
ScriptContext.Submit oEvent
End Sub
'******************************************************************************
' 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()