Check Services to monitor regkey WA

Check_services_to_monitor_registrykey.WriteAction (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsSystem.PrivilegedMonitoringAccount
InputTypeSystem.BaseData

Member Modules:

ID Module Type TypeId RunAs 
Script WriteAction Microsoft.Windows.ScriptWriteAction Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$Timeout Seconds

Source Code:

<WriteActionModuleType ID="Check_services_to_monitor_registrykey.WriteAction" Accessibility="Internal" RunAs="System!System.PrivilegedMonitoringAccount" Batching="false">
<Configuration>
<xsd:element name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="Script" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>Check_services_to_monitor_registrykey.js</ScriptName>
<Arguments/>
<ScriptBody><Script>
// Event Constants
var EVENT_SOURCE = "Exchange MOM";
var EVENT_TYPE_SUCCESS = 0;
var EVENT_TYPE_ERROR = 1;
var EVENT_TYPE_WARNING = 2;
var EVENT_TYPE_INFORMATION = 4;

var oAPI = new ActiveXObject("Mom.ScriptAPI");

function CreateEvent(lngEventID, lngEventType, strMsg)
{
oAPI.LogScriptEvent(EVENT_SOURCE, lngEventID, lngEventType, strMsg);
}

function EchoEvent(lngEventID, lngEventType, strMsg)
{
var sevString;

switch(lngEventType)
{
case EVENT_TYPE_SUCCESS: sevString = "Success"; break;
case EVENT_TYPE_ERROR: sevString = "Error"; break;
case EVENT_TYPE_WARNING: sevString = "Warning"; break;
case EVENT_TYPE_INFORMATION: sevString = "Infomation"; break;
}

if (lngEventType != EVENT_TYPE_SUCCESS)
{
WScript.Echo(EVENT_SOURCE , "Event ID:" , lngEventID , "Severity: " , sevString);
WScript.Echo(strMsg);
}
}

function HResultToString(hresult)
{
return "0x" + (hresult &lt; 0 ? hresult + 0x100000000 : hresult).toString(16).toUpperCase() + "(" + hresult +")";
}


//Copyright (c) Microsoft Corporation. All rights reserved.
//************************************************************************
// $ScriptName: "Check 'services to monitor' registry key" $
//
// Purpose - Check if the registry key was created and its content
//
// $File: Check_services_to_monitor_registry_key.js $
//
// $Date: 2004/05/03 20:59:12 $ $Revision: 3 $
//************************************************************************
// Event Constants
EVENT_SOURCE = "Check 'services to monitor' registry key";
// Event ID Constants
var EVENT_ID_BASE_STATE_OK = 100000;

UNEXPECTED_EXCEPTION_EVENT_ID = 9016
SERVICES_NOT_MONITORED_EVENT_ID = 9962;
NO_MONITORED_SVCS_REGKEY_EVENT_ID = 9963;
NORMAL = 0;
NOT_RUNNING = -1;
NOT_INSTALLED = -2;
NO_REGKEY_SENTINEL = "...";
MONITORED_SVCS_REGKEY = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Exchange MOM\\Monitored Services";
VerifyServicesToMonitorRegKey:
try {
strSvcNames = GetServicesNames(MONITORED_SVCS_REGKEY);
if (strSvcNames == NO_REGKEY_SENTINEL) {
// Do nothing the event was generated inside GetServicesNames
}
else if (strSvcNames == "" || strSvcNames == MONITORED_SVCS_REGKEY) {
CreateEvent(SERVICES_NOT_MONITORED_EVENT_ID, EVENT_TYPE_INFORMATION,"The registry key to specify the list of services to monitor is empty.");
}
else
{
CreateEvent(10000, EVENT_TYPE_INFORMATION, "Registry Key Check Successful");
}
}
catch(err) {
CreateEvent(
UNEXPECTED_EXCEPTION_EVENT_ID,
EVENT_TYPE_ERROR,
"The script aborted its execution due to the following error:\r\rError source: " + err.source + "\rError description: " + err.description + "\rError number: " + HResultToString(err.number));
}
function GetServicesNames(strEntry)
{
try {
objShell = new ActiveXObject("WScript.Shell");
strServicesNames = objShell.RegRead(strEntry);
}
catch(err) {
strServicesNames = NO_REGKEY_SENTINEL;
CreateEvent(
NO_MONITORED_SVCS_REGKEY_EVENT_ID,
EVENT_TYPE_SUCCESS,
"Cannot read the registry key containing the list of services to monitor.\rReason: " + err.description + "\rError number: " + HResultToString(err.number));
}
return (strServicesNames);
}

</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="Script"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>