How to: Get and Set WMI Object Properties
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
To read and write Windows Management Instrumentation (WMI) object property values, you:
- Get and set property and qualifier values.
- Load and save configurations.
Getting and Setting Properties on WMI Objects
Use properties to provide information about the characteristics of a WMI object. For more information about Speech Server WMI classes, see Speech Server WMI Classes.
To read property values
Use code similar to the following sample.
Note
All Speech Server classes inherit from the SWbemObject object, which explains why the SWbemObject.Properties_ property is available in the following sample.
Set objMSS = GetObject("winmgmts:root\MSSV2:MSS=@") ' Read each member of SWbemObject.Properties_ For Each p in objMSS.Properties_ ' Display the values of the Name and Value properties of the SWbemProperty object If p.IsArray Then WScript.Echo p.Name, "=", Join(p.Value) Else WScript.Echo p.Name, " = ", p.Value End If Next
To write property values of Speech Server objects
To write a property value, you must, at a minimum, retrieve an instance of the class containing the property, assign the property a value, and use the Put_ method to update the value in the object. The following sample gets the MSS object (using the GetObject function), sets the UpperMemoryThreshold property, and saves the change.
Set objMSS = GetObject("winmgmts:root\MSSV2:MSS=@") objMSS.UpperMemoryThreshold=1800 objMSS.Put_()
Reading Qualifiers on WMI Objects
A qualifier is a tag that provides additional information about a WMI object, method, or property.
To gain access to a WMI object's qualifiers
Use the SWbemObject.Qualifiers_ property, as shown in the following sample.
Set p = objMSS.Properties_(strProperty) If strNewValue <> "" Then 'p is a MSS property variable p.Value = strNewValue Else d = p.Qualifiers_("DefaultValue") p.Value = d End If
Loading and Saving Configurations
To load values from a configuration file
Use the VBScript Split function and FileSystemObject to parse the file and read property values, as shown in the following sample.
Use the SWbemObjectProperties_ property to store the values read from the configuration file, and use the SWbemObjectPut_ method to update the server instance with those values.
For Each line in Split(f.ReadAll, vbCrLf) ' Omit empty lines and comments ' ... ' Split line into name and value parts ' ... Set p = objMSS.Properties_(strName) If Not Err Then If p.IsArray Then p.Value = Join(strValue) Else p.Value = strValue End If If Err Then WScript.Echo "Failed to assign " & strName & ": " & Err.Description : Err.Clear End If Else WScript.Echo "No such property: " & strName : Err.Clear End If Next ' Update WMI with modified instance objMSS.Put_
To save a server configuration to a file
Use the SWbemObjectProperties_ property to provide the collection of properties on the server, as shown in the following sample.
Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.CreateTextFile(strFilename, true) ' Write all configuration settings For Each p In objMSS.Properties_ If p.IsArray Then f.WriteLine p.Name & ":" & Join(p.Value) Else f.WriteLine p.Name & ":" & p.Value End If Next
Use the VBScript WriteLine method to write property values to a file.