Previous Section Table of Contents Next Section

The All-Purpose WMI Update Script

Querying is easy, but what about updating information in WMI? Just as easy. Start with the basic query template. Instead of echoing property information, however, simply use one of the class' methods, which are documented in the MSDN Library. Here's how to find the Library.

  1. Go to http://msdn.microsoft.com/library.

  2. In the left-hand menu tree, expand Setup and System Administration.

  3. Expand Windows Management Instrumentation.

  4. Expand SDK Documentation.

  5. Expand WMI Reference.

  6. Expand WMI Classes.

  7. Expand Win32 Classes.

  8. Expand the appropriate category, such as Computer System Hardware Classes, for the class you're interested in.

  9. Expand the class itself for a listing of methods, or click on the class for a list of properties.

Take the Win32_NetworkAdapterConfiguration class as an example. This class has a property named DHCPEnabled, which reads True or False. It seems that setting this to True would enable DHCP, but reading the documentation indicates that this particular property is read-only. However, expanding the class definition shows a method named EnableDHCP that looks like just the thing. The following script would enable DHCP on the network adapters in a computer.


Dim strComputer

Dim objWMIService

Dim colItems



strComputer = "."

Set objWMIService = GetObject( _

 "winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery( _

 "Select * from Win32_NetworkAdapterConfiguration",,48)



For Each objItem on colItems

 objItem.EnableDHCP

Next

Notice that this updated script looks a lot like the query script. In fact, I started with the exact same code. That's how easy it can be to update computer configurations by using WMI.

    Previous Section Table of Contents Next Section