Previous Topic

Next Topic

Microsoft Visual Basic Scripting Edition examples

You can write scripts to obtain data from the Insight Providers using Microsoft® Visual Basic Scripting Edition (VBScript) or any other scripting language that supports Microsoft® ActiveX.

The following are example codes for accessing Insight Provider data using VBScript code.

This VBScript code is used to display computer system operational status information:

strComputer = "."

strNamespace = "\root\hpq"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & strNamespace)

Set colComputerSystem = objWMIService.ExecQuery("Select * from HP_WinComputerSystem")

For Each objComputerSystem in colComputerSystem

WScript.Echo "Caption: " & objComputerSystem.Caption

For Each objStatusDescription in objComputerSystem.StatusDescriptions

WScript.Echo "Status description: " & objStatusDescription

Next

For Each objOperationalStatus in objComputerSystem.OperationalStatus

WScript.Echo "Operational status: " & objOperationalStatus

Next

Next

The following VBScript code is used to display system firmware version:

strComputer = "."

strNamespace = "\root\hpq"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & strNamespace)

Set colSystemROMFirmware = objWMIService.ExecQuery("Select * from HP_SystemROMFirmware")

For Each objSystemROMFirmware in colSystemROMFirmware

WScript.Echo "Caption: " & objSystemROMFirmware.Caption

WScript.Echo "Version: " & objSystemROMFirmware.VersionString

WScript.Echo

Next

This VBScript code is used to display computer system chassis model name, serial number and asset tag:

strComputer = "."

strNamespace = "\root\hpq"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & strNamespace)

Set colComputerSystemChassis = objWMIService.ExecQuery("Select * from HP_ComputerSystemChassis")

For Each objComputerSystemChassis in colComputerSystemChassis

WScript.Echo "Model: " & objComputerSystemChassis.Model

WScript.Echo "Serial number: " & objComputerSystemChassis.SerialNumber

WScript.Echo "Asset tag: " & objComputerSystemChassis.UserTracking

Next

This VBScript code is used to list system memory modules and their capacities:

strComputer = "."

strNamespace = "\root\hpq"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & strNamespace)

Set colMemoryModule = objWMIService.ExecQuery("Select * from HP_MemoryModule")

For Each objMemoryModule in colMemoryModule

WScript.Echo "Caption: " & objMemoryModule.Caption

WScript.Echo "Capacity (bytes): " & objMemoryModule.Capacity

Wscript.Echo

Next

This VBScript code is used to list system processors, current clock speed, and the number of enabled cores:

strComputer = "."

strNamespace = "\root\hpq"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & strNamespace)

Set colProcessor = objWMIService.ExecQuery("Select * from HP_Processor")

For Each objProcessor in colProcessor

WScript.Echo "Caption: " & objProcessor.Caption

WScript.Echo "Description: " & objProcessor.Description

WScript.Echo "Current clock speed (MHz): " & objProcessor.CurrentClockSpeed

WScript.Echo "Number of enabled cores: " & objProcessor.NumberOfEnabledCores

Wscript.Echo

Next

This VBScript code is used to list fans and operational status information:

strComputer = "."

strNamespace = "\root\hpq"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & strNamespace)

Set colFan = objWMIService.ExecQuery("Select * from HP_WinFan")

For Each objFan in colFan

WScript.Echo "Caption: " & objFan.Caption

WScript.Echo "Description: " & objFan.Description

For Each objStatusDescription in objFan.StatusDescriptions

WScript.Echo "Status description: " & objStatusDescription

Next

For Each objOperationalStatus in objFan.OperationalStatus

WScript.Echo "Operational status: " & objOperationalStatus

Next

WScript.Echo

Next

This VBScript code is used to clear the record log:

strComputer = "."

strNamespace = "\root\hpq"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & strNamespace)

Set colCommonRecordLog = objWMIService.ExecQuery("Select * from HPQ_CommonRecordLog")

Wscript.Echo "Clearing the record logÂ…"

For Each objCommonRecordLog in colCommonRecordLog

objCommonRecordLog.ClearLog()

Next

This VBScript code is used to receive an alert indication:

strComputer = "."

strNamespace = "\root\hpq"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & strNamespace)

Set objIndication = objWMIService.ExecNotificationQuery("SELECT * FROM HP_AlertIndication")

Wscript.Echo "Waiting for alert indication..."

Set objReceivedIndication = objIndication.NextEvent

WScript.Echo "Provider Name = " & objReceivedIndication.ProviderName

WScript.Echo "Event ID = " & objReceivedIndication.EventID

WScript.Echo "Severity = " & objReceivedIndication.PerceivedSeverity

WScript.Echo "Description = " & objReceivedIndication.Description