Lenovo WinComputer DiscoveryBase Repository

IBM.WinComputer.DiscoveryBase.Repository (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource IBM.WinComputer.DiscoveryBase.RepositoryHWTable Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Lenovo WinComputer DiscoveryBase Repository Interval Seconds
TimeoutSecondsint$Config/TimeoutSeconds$Lenovo WinComputer DiscoveryBase Repository Timeout Seconds
SyncTimestring$Config/SyncTime$Lenovo WinComputer DiscoveryBase Repository Sync Time

Source Code:

<DataSourceModuleType ID="IBM.WinComputer.DiscoveryBase.Repository" Accessibility="Internal">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="SyncTime" type="xsd:string"/>
<xsd:element name="ScriptName" type="xsd:string"/>
<xsd:element name="Arguments" type="xsd:string"/>
<xsd:element name="ScriptBody" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" ParameterType="int" Selector="$Config/IntervalSeconds$"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="int" Selector="$Config/TimeoutSeconds$"/>
<OverrideableParameter ID="SyncTime" ParameterType="string" Selector="$Config/SyncTime$"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="HardwareIDs!IBM.WinComputer.DiscoveryBase.RepositoryHWTable">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime>$Config/SyncTime$</SyncTime>
<ScriptName>$Config/ScriptName$</ScriptName>
<Arguments>$Config/Arguments$</Arguments>
<ScriptBody><Script>

'Option Explicit

'Debug Log Definition
Const HKEY_LOCAL_MACHINE = &amp;H80000002
Const DEBUG_INFO_KEY = "SOFTWARE\Lenovo\Lenovo SCOM MP\Debug"
Const DEBUG_LEVEL_NAME = "Level"
Const ERROR_LEVEL = 1
Const WARNING_LEVEL = 2
Const WARNING_LEVEL_DEV = 3
Const INFO_LEVEL = 4
Const INFO_LEVEL_FUNCTION = 5
Const INFO_LEVEL_DETAIL = 6
Const WINEVENT_FILTER_KEY = "SOFTWARE\Lenovo\Lenovo SCOM MP\WinEventFilter"
Const WINEVENT_FILTER_NAME = "FilterOn"

Const WINEVENT_LICENSE_KEY = "SOFTWARE\Lenovo\Lenovo SCOM MP\LicenseValidate"
Const WINEVENT_LICENSE_NAME = "LicensedValue"

'WMI Macro Definition for all Management Software
Const CIMV2_NAMESPACE = "root/cimv2"
Const WMI_NAMESPACE = "root/wmi"
Const SMBIOS_TABLE_WMI_CLASS = "MSSmBios_RawSMBiosTables"
const IPMI_SMBIOS_RECORD_TYPE = 38
Const OS_CIMV2_CLASS = "Win32_OperatingSystem"
Const SERVICE_CIMV2_CLASS = "Win32_Service"
Const DRIVER_CIMV2_CLASS = "Win32_SystemDriver"

Const ADPT_NAMESPACE = "root/adpt"
Const SERVERAID_ADPT_CLASS = "ADPT_ControllerProduct"

Const SYSTEM_PRODUCT_CIMV2_CLASS = "Win32_ComputerSystemProduct"
Const COMPUTER_SYSTEM_CIMV2_CLASS = "Win32_ComputerSystem"
Const IBMSD_NAMESPACE = "root/ibmsd"
Const IBMSE_NAMESPACE = "root/ibmse"
Const IBMSD_SOFTWAREIDENTITY_CLASS = "IBMSD_SoftwareIdentity"
Const DA_IBMSD_CLASS = "IBMPSG_DirectorAgent"
Const PNPENTITY_CIMV2_CLASS = "Win32_PnPEntity"
Const BIOS_IBMSD_CLASS = "IBMPSG_BIOS"


Const LSI_NAMESPACE = "root/LSI_IR_1_2_0"
Const RAIDCARD_LSI_CLASS = "LSI_RAID_ProductCard"
Const LSI_MR_NAMESPACE = "root/LSI_MR_1_2_0"
Const LSI_MEGARAIDCARD_CLASS = "LSIESG_MegaRAIDProduct"
Const PHYSICAL_MEMORY_IBMSD_CLASS = "IBMPSG_PhysicalMemory"
'For Network Device
Const NETWORK_ADAPTER_IBMSD_CLASS = "IBMPSG_PhysicalNetworkAdapter"
Const NETWORK_ADAPTER_IBMSE_CLASS = "IBMSD_NetworkCard"
Const IMM_IPAddress_Class ="IBMx_MgmtHwIPProtocolEndPoint"

'
'Instance name for hw components of unlicensed system
'
Const PROCESSOR_INSTANCE_NAME = "Physical Processor"
Const IMM_INSTANCE_NAME = "BMC or IMM"
Const MEMORY_INSTANCE_NAME = "Phsical Memory"
Const FAN_INSTANCE_NAME = "Cooling Fan"
Const NETWORK_INSTANCE_NAME = "Network Adapter"
Const POWERSUPPLY_INSTANCE_NAME = "Power Supply"
Const VOLTAGE_INSTANCE_NAME = "Voltage Sensor"
Const TEMPERATURE_INSTANCE_NAME = "Temperature Sensor"
Const SR_INSTANCE_NAME = "ServeRAID"
Const MR_INSTANCE_NAME = "ServeRAID-MR"
Const IR_INSTANCE_NAME = "LSI Integrated RAID"
Const NA = "Not Available"

Const SW_IBM_DA = 1
Const SW_OSA_IPMI = 2
Const SW_IBM_IPMILAYER = 3
Const SW_MS_IPMI = 4
Const SW_IBM_RSA = 5
Const SW_IBM_SERVERAID = 6
Const SW_IBM_MEGARAID = 7

Const IBMHWMP_LICENSE_KEY = "SOFTWARE\IBM\Systems Management Integrations\LicenseEndpoint"
Const LenovoHWMP_LICENSE_KEY = "SOFTWARE\Lenovo\Systems Management Integrations\LicenseEndpoint"
Const IBMHWMP_LICENSE_TOKEN_NAME = "v1-0002.A"
Const IBMHWMP_LICENSE_LEVEL = "Level"

SetLocale("en-us")

Dim oAPI, oDiscoveryData, machineType

Dim debug, oReg,RC_Code, ScriptName, EventID

ScriptName = "$Config/ScriptName$"

debug = -1
Set oReg = GetObject("winmgmts://localhost/root/default:StdRegProv")
If (not(oReg is nothing)) Then
RC_Code = oReg.GetStringValue(HKEY_LOCAL_MACHINE, DEBUG_INFO_KEY, DEBUG_LEVEL_NAME, debug)
If (RC_Code &lt;&gt;0) Then
debug = -1
End If
End If
Set oAPI = SCOMCreateObject("MOM.ScriptAPI")
$Config/ScriptBody$

Sub LogDebugString(debugString, debugLevel)

If (Int(debug) &gt;= Int(debugLevel)) Then
Call oAPI.LogScriptEvent(ScriptName, EventID, DebugLevelToLogLevel(debugLevel), debugString)
End If

End Sub
Function DebugLevelToLogLevel(debugLevel)
DebugLevelToLogLevel = 4
If debugLevel &lt;= 1 then
DebugLevelToLogLevel = 1
ElseIF debugLevel &lt;= 3 then
DebugLevelToLogLevel = 2
Else
DebugLevelToLogLevel = 4
End If
End Function

Function BMCPresented()
Dim bWS08, bInACPI, bInSMBIOS
Dim osVersion, spVersion
Dim oObjectItem, oManagementTargetCollection, iResult
Const BMC_ACPIINFO = "ACPI\IPI"

Call LogDebugString("Entering BMCPresented", INFO_LEVEL_FUNCTION)

bWS08 = -1
bInACPI = -1
bInSMBIOS = -1

BMCPresented = -1
osVersion = ""
spVersion = ""

If GetOSInfo(osVersion, spVersion) &lt; 0 Then
Call LogDebugString("Could not get OS Info", WARNING_LEVEL_DEV)
End If
If(StrComp(osVersion, "6.0.0000") &gt;= 0) Then
'Windows 2008 or later
Call LogDebugString("OS is Windows 2008 or later", INFO_LEVEL_DETAIL)
bWS08 = 1
End If

iResult = GetWMIObjectCollection(CIMV2_NAMESPACE, PNPENTITY_CIMV2_CLASS, oManagementTargetCollection)
If (iResult &gt; 0) Then
For Each oObjectItem in oManagementTargetCollection
If (InStr(CStr(oObjectItem.DeviceID), BMC_ACPIINFO) &lt;&gt; 0) Then
'BMCPresented = 1
bInACPI = 1
Call LogDebugString("BMC Presented in ACPI", INFO_LEVEL_DETAIL)
Exit For
End If
Next
End If

iResult = GetWMIObjectCollection(WMI_NAMESPACE, SMBIOS_TABLE_WMI_CLASS, oManagementTargetCollection)
If (iResult &gt; 0 ) Then
iResult = wmiRawSMBiosCountRecords( oManagementTargetCollection, IPMI_SMBIOS_RECORD_TYPE )
If iResult &gt; 0 Then
'BMCPresented = 2
bInSMBIOS = 1
Call LogDebugString("BMC Presented in SMBIOS, but BIOS need update", INFO_LEVEL_DETAIL)

End If
End If

If bWS08 &gt; 0 And bInACPI &gt; 0 Then
BMCPresented = 1
ElseIf bWS08 &gt; 0 And bInACPI &lt; 0 And bInSMBIOS &gt; 0 Then
BMCPresented = 3 ' need update
ElseIf bWS08 &lt; 0 And bInSMBIOS &gt; 0 Then
BMCPresented = 2
End If

If BMCPresented &lt;0 Then
Call LogDebugString("BMC not Presented", INFO_LEVEL_DETAIL)
End If
Call LogDebugString("End of BMCPresented()", INFO_LEVEL_FUNCTION)
End Function

Function wmiRawSMBiosCountRecords( colRawSMBIOSes, thisRecordType )

dim nMatches
nMatches = 0
Call LogDebugString("Entering wmiRawSMBiosCountRecords()", INFO_LEVEL_FUNCTION)
dim smbiosTable
for each smbiosTable in colRawSMBIOSes

dim tableData, tablePos, tableSize
tableData = smbiosTable.SMBiosData
tablePos = 0
tableSize = smbiosTable.Size

dim recordType, recordLen, recordHnd
do while ( tablePos &lt; tableSize )
' Look up the type in the formatted section.
recordType = tableData( tablePos )
recordLen = tableData( tablePos+1 )
recordHnd = tableData( tablePos+3 )*256 + tableData( tablePos+2 )

if ( recordType = thisRecordType ) then
nMatches = nMatches + 1
end if
tablePos = tablePos + recordLen

' Skip over the unformatted section (of null-terminated strings).
do
do until ( tableData(tablePos) = 0 )
tablePos = tablePos + 1
loop
tablePos = tablePos + 1 ' Skip the string terminater.
if ( tableData(tablePos) = 0 ) then
exit do ' Now the string sec terminates.
end if
tablePos = tablePos + 1 ' Skip the 1st (non-null) char.
loop
tablePos = tablePos + 1 ' Skip the section terminator.
loop
next

wmiRawSMBiosCountRecords = nMatches
Call LogDebugString("wmiRawSMBiosCountRecords = " &amp; wmiRawSMBiosCountRecords, INFO_LEVEL_DETAIL)
Call LogDebugString("End of wmiRawSMBiosCountRecords()", INFO_LEVEL_FUNCTION)
End Function


Function GetAccurateName(ByVal RawName)
'This function is used to remove the """ characters in the file's name string
'Input "xxxxxxxx.xxx"
'Output xxxxxxxx.xxx
Dim tmpName,Name
tmpName = Replace(RawName, """", " ")
Call LogDebugString(tmpName, INFO_LEVEL_DETAIL)
Name = Trim(tmpName)
GetAccurateName = Name
End Function

Function IsRegExpMatched(ByVal strTarget, ByVal strRegExp)
'This function is to see if the specified string matches the given regular expression;
'it returns True if matched; False if not.
Call LogDebugString("Entering IsRegExpMatched()", INFO_LEVEL_FUNCTION)
IsRegExpMatched = -1

Dim oRegExp
Set oRegExp = New RegExp
oRegExp.IgnoreCase = False
oRegExp.Pattern = strRegExp

IsRegExpMatched = oRegExp.Test(strTarget)
Call LogDebugString("End of IsRegExpMatched()", INFO_LEVEL_FUNCTION)
End Function

Function GetOSInfo(ByRef osVersion, ByRef spVersion)
Call LogDebugString("Entering GetOSInfo", INFO_LEVEL_FUNCTION)
GetOSInfo = -1

Dim iResult, oCollection, oObjectItem
'Get OS and SP version info
iResult = GetWMIObjectCollection(CIMV2_NAMESPACE, OS_CIMV2_CLASS, oCollection)
If (iResult &gt; 0) Then
For Each oObjectItem in oCollection
If InStr(oObjectItem.Manufacturer, "Microsoft Corporation") &lt;&gt; 0 Then
osVersion = oObjectItem.Version
spVersion = oObjectItem.ServicePackMajorVersion
GetOSInfo = 1
Call LogDebugString("osVersion =" &amp; oObjectItem.Version, INFO_LEVEL_DETAIL)
Exit For
End If
Next
Else
Call LogDebugString("Could not get OS Info", WARNING_LEVEL)
End If
Call LogDebugString("End of GetOSInfo", INFO_LEVEL_FUNCTION)
End Function

Function IsWin2k3r2()
Call LogDebugString("Entering IsWin2k3r2", INFO_LEVEL_FUNCTION)
IsWin2k3r2 = 0

Dim iResult, oCollection, oObjectItem, osVersion
'Get OS and SP version info
iResult = GetWMIObjectCollection(CIMV2_NAMESPACE, OS_CIMV2_CLASS, oCollection)
If (iResult &gt; 0) Then
For Each oObjectItem in oCollection
If InStr(oObjectItem.Manufacturer, "Microsoft Corporation") &lt;&gt; 0 Then
osVersion = oObjectItem.Version
if ( IsRegExpMatched(osVersion, "^5\.2\.") ) then
If InStr(oObjectItem.OtherTypeDescription, "R2") Then
IsWin2k3r2 = 1
Call LogDebugString("IsWin2k3r2 - Win2k3 r2 - osVersion: " &amp; oObjectItem.Version &amp; _
" - R number: " &amp; oObjectItem.OtherTypeDescription &amp; _
" - SP: " &amp; oObjectItem.ServicePackMajorVersion, INFO_LEVEL_DETAIL)
Exit For
End If
End If
End If
Next
Else
Call LogDebugString("IsWin2k3r2 - Could not get OS Info", WARNING_LEVEL)
End If
Call LogDebugString("End of IsWin2k3r2 - Return: " &amp; IsWin2k3r2, INFO_LEVEL_FUNCTION)
End Function

Function RSAPresented()
Call LogDebugString("Entering RSAPresented", INFO_LEVEL_FUNCTION)
RSAPresented = -1

Dim oObjectItem, oManagementTargetCollection, iResult
Const RSA_USBINFO_NOSTORAGE = "USB\VID_04B3&amp;PID_4001"
Const RSA_USBINFO_WSTORAGE = "USB\VID_04B3&amp;PID_4003"

iResult = GetWMIObjectCollection(CIMV2_NAMESPACE, PNPENTITY_CIMV2_CLASS, oManagementTargetCollection)
If (iResult &gt; 0) Then
For Each oObjectItem in oManagementTargetCollection
If (InStr(CStr(oObjectItem.DeviceID), RSA_USBINFO_NOSTORAGE) &lt;&gt; 0) or (InStr(CStr(oObjectItem.DeviceID), RSA_USBINFO_WSTORAGE) &lt;&gt; 0) Then
RSAPresented = 1
Call LogDebugString("RSA Presented", INFO_LEVEL_DETAIL)
Exit Function
End If
Next
End If
Call LogDebugString("RSA not Presented", INFO_LEVEL_DETAIL)
End Function

Function ServeRAIDPresented(ByRef sRAIDController)
Call LogDebugString("Entering ServeRAIDPresented", INFO_LEVEL_FUNCTION)
ServeRAIDPresented = -1

Dim oObjectItem, oManagementTargetCollection, iResult, I

iResult = GetWMIObjectCollection(CIMV2_NAMESPACE, PNPENTITY_CIMV2_CLASS, oManagementTargetCollection)
If (iResult &gt; 0) Then
For Each oObjectItem in oManagementTargetCollection
For I = 0 To UBound(ServeRAIDPCIInfoTable)
If (InStr(CStr(oObjectItem.DeviceID), ServeRAIDPCIInfoTable(I)(PCI_INFO)) &lt;&gt; 0) Then
ServeRAIDPresented = 1
If(sRAIDController = "None" ) or I = 0 Then
sRAIDController = ServeRAIDPCIInfoTable(I)(DEVICE_NAME)
Else
sRAIDController = sRAIDController + ", " + ServeRAIDPCIInfoTable(I)(DEVICE_NAME)
End If
End If
Next
Next
End If
Call LogDebugString("sRAIDController = " &amp; sRAIDController, INFO_LEVEL_DETAIL)
Call LogDebugString("End of ServeRAIDPresented()", INFO_LEVEL_FUNCTION)
End Function


Function MegaRAIDPresented(ByRef sRAIDController)
Call LogDebugString("Entering MegaRAIDPresented", INFO_LEVEL_FUNCTION)
MegaRAIDPresented = -1

Dim oObjectItem, oManagementTargetCollection, iResult, I

iResult = GetWMIObjectCollection(CIMV2_NAMESPACE, PNPENTITY_CIMV2_CLASS, oManagementTargetCollection)
If (iResult &gt; 0) Then
For Each oObjectItem in oManagementTargetCollection
For I = 0 To UBound(MegaRAIDPCIInfoTable)
If (InStr(CStr(oObjectItem.DeviceID), MegaRAIDPCIInfoTable(I)(PCI_INFO)) &lt;&gt; 0) Then
MegaRAIDPresented = 1
If(sRAIDController = "None" ) or I = 0 Then
sRAIDController = MegaRAIDPCIInfoTable(I)(DEVICE_NAME)
Else
sRAIDController = sRAIDController + ", " + MegaRAIDPCIInfoTable(I)(DEVICE_NAME)
End If
End If
Next
Next
End If
Call LogDebugString("sRAIDController = " &amp; sRAIDController, INFO_LEVEL_DETAIL)
Call LogDebugString("End of MegaRAID MegaRAIDPresented()", INFO_LEVEL_FUNCTION)
End Function

Function IntegratedRAIDPresented(ByRef sRAIDController)
Call LogDebugString("Entering IntegratedRAIDPresented", INFO_LEVEL_FUNCTION)
IntegratedRAIDPresented = -1

Dim oObjectItem, oManagementTargetCollection, iResult, I

iResult = GetWMIObjectCollection(CIMV2_NAMESPACE, PNPENTITY_CIMV2_CLASS, oManagementTargetCollection)
If (iResult &gt; 0) Then
For Each oObjectItem in oManagementTargetCollection
For I = 0 To UBound(IntegratedRAIDPCIInfoTable)
If (InStr(CStr(oObjectItem.DeviceID), IntegratedRAIDPCIInfoTable(I)(PCI_INFO)) &lt;&gt; 0) Then
IntegratedRAIDPresented = 1
If(sRAIDController = "None" ) or I = 0 Then
sRAIDController = IntegratedRAIDPCIInfoTable(I)(DEVICE_NAME)
Else
sRAIDController = sRAIDController + ", " + IntegratedRAIDPCIInfoTable(I)(DEVICE_NAME)
End If
Call LogDebugString("sRAIDController = " &amp; sRAIDController, INFO_LEVEL_DETAIL)
End If
Next
Next
End If
Call LogDebugString("sRAIDController = " &amp; sRAIDController,INFO_LEVEL_DETAIL)
Call LogDebugString("End of IntegratedRAIDPresented()", INFO_LEVEL_FUNCTION)
End Function

Function GetRAIDPresented(ByRef sRAIDController)
Call LogDebugString("Entering GetRAIDPresented", INFO_LEVEL_FUNCTION)
GetRAIDPresented = -1

Dim oObjectItem, oManagementTargetCollection, iResult, I

iResult = GetWMIObjectCollection(CIMV2_NAMESPACE, PNPENTITY_CIMV2_CLASS, oManagementTargetCollection)
If (iResult &gt; 0) Then
For Each oObjectItem in oManagementTargetCollection
If (InStr(oObjectItem.Name, "RAID") &lt;&gt; 0) Then
GetRAIDPresented = 1
If (sRAIDController = "None" ) Then
sRAIDController = oObjectItem.Name
Else
sRAIDController = sRAIDController + ", " + oObjectItem.Name
End If
Call LogDebugString("sRAIDController = " &amp; sRAIDController, INFO_LEVEL_DETAIL)
End If
Next
End If
Call LogDebugString("sRAIDController = " &amp; sRAIDController,INFO_LEVEL_DETAIL)
Call LogDebugString("End of GetRAIDPresented()", INFO_LEVEL_FUNCTION)
End Function


'IBMx_MgmtHwIPProtocolEndPoint.IPv4Address
Function GetIMMIPv4Address()
Call LogDebugString("Entering GetIMMIPv4Address", INFO_LEVEL_FUNCTION)
GetIMMIPv4Address = ""

Dim oObjectItem, oManagementTargetCollection, iResult, I
'DiscoveryBase.Repository
iResult = GetWMIObjectCollection(IBMSD_NAMESPACE, IMM_IPAddress_Class, oManagementTargetCollection)
If (iResult &gt; 0) Then
For Each oObjectItem in oManagementTargetCollection
GetIMMIPv4Address = CStr(oObjectItem.IPv4Address)
Exit For' only get the first one
Next
End If
Call LogDebugString("GetIMMIPv4Address = " &amp; GetIMMIPv4Address,INFO_LEVEL_DETAIL)
Call LogDebugString("End of GetIMMIPv4Address()", INFO_LEVEL_FUNCTION)
End Function

Function GetWMIObjectCollection(ByVal oNameSpace, ByVal oClassName, ByRef oObjectCollection)

Call LogDebugString("Entering GetWMIObjectCollection(" + oNameSpace + ":" + oClassName + ")", INFO_LEVEL_FUNCTION)
GetWMIObjectCollection = -1
Dim e
Set e = New Error
On Error Resume Next
Set oObjectCollection = GetObject("winmgmts:{impersonationLevel=impersonate}//" &amp; _
"." &amp; "/" &amp; oNameSpace &amp; ":" &amp; oClassName).Instances_

'Check WMI communications...
If (oObjectCollection is nothing) Then
Call LogDebugString("No " + oClassName + " class in the namespace", INFO_LEVEL_DETAIL)
Exit Function
End If

If (oObjectCollection.Count = 0) Then 'Try to count system instances...
Call LogDebugString("No instance on " + oClassName, INFO_LEVEL_DETAIL)
GetWMIObjectCollection = 0
Exit Function
Else
If (Err.number &lt;&gt; 0) Then
Call LogDebugString("Error on accessing " + oClassName, ERROR_LEVEL)
Exit Function
Else
GetWMIObjectCollection = 1
End If
End If

End Function

Function SCOMCreateObject(ByVal sProgramId)

Dim oError
Set oError = New Error

On Error Resume Next
Set SCOMCreateObject = CreateObject(sProgramId)
oError.Save
On Error Goto 0

If (oError.Number &lt;&gt; 0) Then
Call LogDebugString("Error to create object", ERROR_LEVEL)
WScript.Quit
End If

End Function

Function ChangeString(ByRef sName)
Dim temp
ChangeString = sName
temp = Replace(sName,"{","")
temp = Replace(temp,"}","")
ChangeString = temp
Call LogDebugString("ChangeString()", INFO_LEVEL_DETAIL)
End Function

Function licKeyValidate( byVal sFeatureId )
' Description:
' Validates the OS instance or IMM oriented license key
' of the given feature of the localhost?
' Possible Return Code:
' 1, if valid but about to expire (in 14 days).
' 0, if valid.
' -1, if no license key is installed.
' -2, if the license key was already expired.
' -3, if the license key is invalid (integrity broken).
' -10, if the IMM-oriented license key was recently changed
' and needs to be reprocessed first.
licKeyValidate = CInt(licKeyValidateRegValue())
End Function

'FOR DEBUG ONLY
Function licKeyValidateRegValue()

Dim oReg, rcCode, iWinEventFiltering
'Dim iWinEventFiltering, set this value to 1 means turn off this filter. 0, turn on.
iWinEventFiltering = "-1"

Call LogDebugString("Entering licKeyValidateRegValue", INFO_LEVEL_DETAIL)

Set oReg = GetObject("winmgmts://localhost/root/default:StdRegProv")
If (not(oReg is nothing)) Then
Dim szValue
rcCode = oReg.GetStringValue(HKEY_LOCAL_MACHINE, WINEVENT_LICENSE_KEY, WINEVENT_LICENSE_NAME, szValue)
If (Not(IsNull(szValue))) Then
iWinEventFiltering = szValue
End If
End If
licKeyValidateRegValue = iWinEventFiltering

End Function

Function GetEndpointLic(ByRef sLicLevel)
'sLicLevel = null
sLicLevel = "None"
'sLicTok = null

'Dim oReg ''' This should already be defined and init'ed globally '''
Dim rcCode,TrialDays,TrialInfo
rcCode = -1

Call LogDebugString("Entering GetEndpointLic", INFO_LEVEL_DETAIL)
TrialInfo= GetEndpointTrialInfo(TrialDays)

''' The registry provider should have already been initialized globally
''' in this script. The LicManager class depends on oReg as a global.
'Set oReg = GetObject("winmgmts://localhost/root/default:StdRegProv")
If (not(oReg is nothing)) Then

'Get the value, refer to "IBM.LicenseServer.Discovery.Provider"
'rcCode = oReg.GetStringValue(HKEY_LOCAL_MACHINE, IBMHWMP_LICENSE_KEY, _
' IBMHWMP_LICENSE_TOKEN_NAME, sLicTok)
'rcCode = oReg.GetStringValue(HKEY_LOCAL_MACHINE, IBMHWMP_LICENSE_KEY, _
' IBMHWMP_LICENSE_LEVEL, sLicLevel)

Dim oLicValidator, aLicLevelERs, oBestLevelER
Set oLicValidator = new LicManager
Call oLicValidator.LoadFromRegistry()
aLicLevelERs = oLicValidator.LevelERs
If IsArray(aLicLevelERs) Then
'sLicTok = oLicValidator.LicenseToken
Call oLicValidator.FindBestFeatLevel(oBestLevelER)
If Not IsNull(oBestLevelER) Then
sLicLevel = oBestLevelER.ToString()
rcCode = 1
Else
Call LogDebugString("The best matched feature level could " + _
"not be obtained on this server", WARNING_LEVEL)
End If
Else
Call LogDebugString("No feature levels activated on this Lenovo License Server", WARNING_LEVEL)
End If
If(TrialInfo=1)Then
If(sLicLevel&lt;&gt;"255.0")Then
sLicLevel="Trial,left "&amp; TrialDays &amp;" days"
rcCode = 1
End If
End If
'If (Not(IsNull(sLicLevel)) And Not(IsEmpty(sLicLevel))) Then
' rcCode = 1
'Else
' sLicLevel = "None"
' rcCode = -1
'End If
'
'If (Not(IsNull(sLicTok)) And Not(IsEmpty(sLicTok))) Then
' rcCode = 1
'Else
' sLicTok = "None"
' rcCode = -1
'End If

End If
GetEndpointLic = rcCode

End Function

'Return:
'1:Yes,trial license available
'-1:No,trial license invalid
'Const IBMHWMP_LICENSE_KEY = "SOFTWARE\IBM\Systems Management Integrations\LicenseEndpoint"
Const IBMHWMP_TRIAL_LICENSE_TOKEN_NAME = "TrialActivation"
Function GetEndpointTrialInfo(ByRef sTrialInfo)

Dim rcCode,sTrialDays
sTrialInfo = "None"
rcCode = -1
Call LogDebugString("Entering GetEndpointTrialInfo", INFO_LEVEL_DETAIL)

set oReg = GetObject( "winmgmts:{impersonationLevel=impersonate}!" &amp; _
"//./root/default:StdRegProv")

call oReg.GetStringValue( HKEY_LOCAL_MACHINE, LenovoHWMP_LICENSE_KEY, IBMHWMP_TRIAL_LICENSE_TOKEN_NAME, sTrialDays )
if IsNull(sTrialDays) Or IsEmpty(sTrialDays) then
call oReg.GetStringValue( HKEY_LOCAL_MACHINE, IBMHWMP_LICENSE_KEY, IBMHWMP_TRIAL_LICENSE_TOKEN_NAME, sTrialDays )
End if

if IsNull(sTrialDays) Or IsEmpty(sTrialDays) then
rcCode=-1
sTrialInfo = "None"
else
rcCode=1
sTrialInfo=sTrialDays
End if

GetEndpointTrialInfo = rcCode

End Function


class LicManager

private m_aLevelERs
public property get LevelERs
LevelERs = m_aLevelERs
end property

private m_sLicToken
public property get LicenseToken
LicenseToken = m_sLicToken
end property

private sub Class_Initialize()
m_aLevelERs = null
m_sLicToken = ""
end sub

public sub LoadFromRegistry()

dim nLevelsLoaded, licenseFlag
nLevelsLoaded = 0
m_aLevelERs = null
m_sLicToken = ""
licenseFlag = 1

dim aKeyEntryNames, aKeyEntryTypes
Call LogDebugString(".. LicManager: loading from registry key '" + _
LenovoHWMP_LICENSE_KEY + "'", INFO_LEVEL_FUNCTION)
Call oReg.EnumValues( HKEY_LOCAL_MACHINE, LenovoHWMP_LICENSE_KEY, _
aKeyEntryNames, aKeyEntryTypes )

if isNull( aKeyEntryNames ) or not(isArray( aKeyEntryNames )) then
Call LogDebugString(".. LicManager: loading from registry key '" + _
IBMHWMP_LICENSE_KEY + "'", INFO_LEVEL_FUNCTION)
Call oReg.EnumValues( HKEY_LOCAL_MACHINE, IBMHWMP_LICENSE_KEY, _
aKeyEntryNames, aKeyEntryTypes )
licenseFlag = 0
end if
if isNull( aKeyEntryNames ) or not(isArray( aKeyEntryNames )) then
exit sub
end if

Call LogDebugString(".. LicManager: # of registry value entries = " + _
CStr(UBound(aKeyEntryNames)+1), INFO_LEVEL_DETAIL)

dim ii
for ii=0 to UBound(aKeyEntryNames)
if 1 = aKeyEntryTypes( ii ) then ' 1 = REG_SZ
if IBMHWMP_LICENSE_TOKEN_NAME = aKeyEntryNames(ii) then
dim sLevelERsEncoded, sLevelERsDecoded, asSplitERs
if licenseFlag = 1 then
call oReg.GetStringValue( HKEY_LOCAL_MACHINE, LenovoHWMP_LICENSE_KEY, _
aKeyEntryNames(ii), sLevelERsEncoded )
else
call oReg.GetStringValue( HKEY_LOCAL_MACHINE, IBMHWMP_LICENSE_KEY, _
aKeyEntryNames(ii), sLevelERsEncoded )
end if
if IsNull(sLevelERsEncoded) Or IsEmpty(sLevelERsEncoded) then
call LogDebugString("!! LicManager: Registry value " + _
aKeyEntryNames(ii) + " null or empty", ERROR_LEVEL)
else
call LogDebugString(".. LicManager: " + aKeyEntryNames(ii) + _
"='" + sLevelERsEncoded + "'", INFO_LEVEL_DETAIL)
m_sLicToken = sLevelERsEncoded
sLevelERsDecoded = fDecode(sLevelERsEncoded)
call LogDebugString(".. LicManager: " + aKeyEntryNames(ii) + _
"='" + sLevelERsDecoded + "' [Decoded]", INFO_LEVEL_DETAIL)
asSplitERs = split(sLevelERsDecoded, vbTab)
if UBound(asSplitERs) &gt;= 0 then
dim jj
for jj=0 to UBound(asSplitERs)
call LogDebugString(".. LicManager: Retrieved '" + _
asSplitERs(jj) + "'", INFO_LEVEL_DETAIL)
dim oLevelER
set oLevelER = new FeatLevelER
if 0 &lt;= oLevelER.ParseLevelER( asSplitERs(jj) ) then
if 0 = nLevelsLoaded then
m_aLevelERs = array( 0 ) ' create a 1-element array of '0'
else
redim preserve m_aLevelERs( nLevelsLoaded )
end if
set m_aLevelERs( nLevelsLoaded ) = oLevelER
nLevelsLoaded = nLevelsLoaded + 1
call LogDebugString("&gt;&gt; LicManager: Parsed " + _
oLevelER.ToString(), INFO_LEVEL)
end if
next
end if
end if
end if
end if
next

end sub ' LoadFromRegistry

public sub FindBestFeatLevel( byRef oBestLevelER )
oBestLevelER = null
if not( isArray( m_aLevelERs ) ) then
exit sub
end if
if UBound(m_aLevelERs) &gt;= 0 then
dim ii, oLevelER
set oBestLevelER = m_aLevelERs(0)
for ii=1 to UBound(m_aLevelERs)
set oLevelER = m_aLevelERs(ii)
if (oLevelER.LevelMajor &gt; oBestLevelER.LevelMajor) Or _
(oLevelER.LevelMajor = oBestLevelER.LevelMajor And _
oLevelER.LevelMinor &gt; oBestLevelER.LevelMinor) then
set oBestLevelER = oLevelER
end if
next
end if
end sub

end class

class FeatLevelER

private m_levelMajor
private m_levelMinor

public property get LevelMajor
LevelMajor = m_levelMajor
end property
public property get LevelMinor
LevelMinor = m_levelMinor
end property

private sub Class_Initialize()
end sub

public function ParseLevelER( byVal sEntryValue )
dim retCode
retCode = 0
on error resume next
dim asSplit
asSplit = split( sEntryValue, "." )
if UBound(asSplit) &lt;&gt; 1 then
call LogDebugString("!! FeatLevelER.ParseLevelER: unexpected number of items in " + _
"feature level record (" + UBound(asSplit) + ")", ERROR_LEVEL)
retCode = -1
else
m_levelMajor = CInt(asSplit(0))
m_levelMinor = CInt(asSplit(1))
call LogDebugString(".. FeatLevelER.ParseLevelER: MajorVersion = " + _
CStr(m_levelMajor) + ", MinorVersion = " + CStr(m_levelMinor), INFO_LEVEL_DETAIL)
end if
on error goto 0
ParseLevelER = retCode
end function

public function ToString()
ToString = CStr(m_levelMajor) + "." + CStr(m_levelMinor)
end function

end class


' N.B. fDecode() is a verbatim copy of the one in HW MP.
' &lt;twoffer&gt; Can this be referenced instead of copied? &lt;/twoffer&gt;
Function fDecode(sStringToDecode)
'This function will decode a Base64 encoded string and returns the decoded string.
Const CharList = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim iDataLength, sOutputString, iGroupInitialCharacter
sStringToDecode = Replace(Replace(Replace(sStringToDecode, vbCrLf, ""), vbTab, ""), " ", "")
iDataLength = Len(sStringToDecode)
If iDataLength Mod 4 &lt;&gt; 0 Then
fDecode = "Bad string passed to fDecode() function."
Exit Function
End If
For iGroupInitialCharacter = 1 To iDataLength Step 4
Dim iDataByteCount, iCharacterCounter, sCharacter, iData, iGroup, sPreliminaryOutString
iDataByteCount = 3
iGroup = 0
For iCharacterCounter = 0 To 3
sCharacter = Mid(sStringToDecode, iGroupInitialCharacter + iCharacterCounter, 1)
If sCharacter = "=" Then
iDataByteCount = iDataByteCount - 1
iData = 0
Else
iData = InStr(1, CharList, sCharacter, 0) - 1
If iData = -1 Then
fDecode = "Bad string passed to fDecode() function."
Exit Function
End If
End If
iGroup = 64 * iGroup + iData
Next
iGroup = Hex(iGroup)
iGroup = String(6 - Len(iGroup), "0") &amp; iGroup
sPreliminaryOutString = Chr(CByte("&amp;H" &amp; Mid(iGroup, 1, 2))) &amp; Chr(CByte("&amp;H" &amp; Mid(iGroup, 3, 2))) &amp; Chr(CByte("&amp;H" &amp; Mid(iGroup, 5, 2)))
sOutputString = sOutputString &amp; Left(sPreliminaryOutString, iDataByteCount)
Next
fDecode = sOutputString
End Function

Class Error
Private lNumber
Private sSource
Private sDescription
Private sHelpContext
Private sHelpFile
Public Sub Save()
lNumber = Err.number
sSource = Err.Source
sDescription = Err.Description
sHelpContext = Err.HelpContext
sHelpFile = Err.helpfile
End Sub
Public Sub Raise()
Err.Raise lNumber, sSource, sDescription, sHelpFile, sHelpContext
End Sub
Public Sub Clear()
lNumber = 0
sSource = ""
sDescription = ""
sHelpContext = ""
sHelpFile = ""
End Sub
Public Default Property Get Number()
Number = lNumber
End Property
Public Property Get Source()
Source = sSource
End Property
Public Property Get Description()
Description = sDescription
End Property
Public Property Get HelpContext()
HelpContext = sHelpContext
End Property
Public Property Get HelpFile()
HelpFile = sHelpFile
End Property
End Class



</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>