Data Source to Read and Write Registry

Dell.WindowsServer.Scalable.RegistryReadWriteDSMT (DataSourceModuleType)

Knowledge Base article:

Summary

DSMT to read and write registry entries on a managed node.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$

Source Code:

<DataSourceModuleType ID="Dell.WindowsServer.Scalable.RegistryReadWriteDSMT" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="Computer" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>registry_read_write.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Config/Computer$</Arguments>
<ScriptBody><Script>
'**********************************************************************************
' Script Name - registry_read_write.vbs
' Author: Rashma N
'
' Description:
' This script reads the registry and creates the resgistry keys Version and LasrRunTime
' On a MN. By default, this discovery runs once in 15 days.
' (c) Copyright Dell Inc. 2015. All rights reserved
'**********************************************************************************
Option Explicit
On Error resume next
SetLocale("en-us")
Dim isKeyPresent, versionKey, lastRunTimeKey
versionKey = "HKEY_LOCAL_MACHINE\Software\Dell Computer Corporation\Server Management Pack Suite\Version"
lastRunTimeKey = "HKEY_LOCAL_MACHINE\Software\Dell Computer Corporation\Server Management Pack Suite\LastRunTime"

isKeyPresent = readRegistry(versionKey)
if(isKeyPresent = false) Then
writeRegistry versionKey,"5.2"
end if
writeRegistry lastRunTimeKey, Date

Dim oArgs
Set oArgs = WScript.Arguments
If oArgs.Count &lt; 2 Then
Wscript.Quit -1
End If

Dim sourceId, managedEntityId, targetComputer
sourceId = oArgs(0)
managedEntityId = oArgs(1)
targetComputer = oArgs(2)

Dim oAPI, oDiscoveryData, oInst
Set oAPI = CreateObject("MOM.ScriptAPI")
set oDiscoveryData = oAPI.CreateDiscoveryData(0, sourceId, managedEntityId)
set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Dell.WindowsServer.Sink']$")
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", targetComputer)
call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Dell Windows Server")
call oInst.AddProperty("$MPElement[Name='Dell.WindowsServer.Sink']/Name$", targetComputer)
call oDiscoveryData.AddInstance(oInst)
Call oAPI.Return(oDiscoveryData)
Set oAPI = Nothing
Err.Clear
Function readRegistry(ByVal regKey)
on error resume next
dim bKey, oShell, isPresent
bKey = false
Set oShell = CreateObject ("WScript.Shell")
bKey = oShell.RegRead(regKey)
if(bKey="") Then
readRegistry = true
else
readRegistry = false
end if
'wscript.echo "readRegistry is " &amp; readRegistry
Err.Clear
End Function
Function writeRegistry(ByVal regKey, ByVal val)
on error resume next
Dim oShell
Set oShell = CreateObject ("WScript.Shell")
oShell.RegWrite regKey, val
Err.Clear
End Function
</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>