Version 5 of TWAPI and WMI

Updated 2006-09-05 17:02:39 by APN

Some examples of using WMI through TWAPI COM support. Note that these are for illustrating use of WMI. Where possible, it is much more efficient to use TWAPI's commands that directly layer on top of the Win32 API.

All examples assume you have initialized with

  package require twapi 1.0
  set wmi [twapi::_wmi]

and remember to do a

  $wmi -destroy

at the end


BIOS

Print BIOS information

  $wmi -with {
    {ExecQuery "select * from Win32_BIOS"}
  } -iterate bios { 
    puts [$bios GetObjectText_]
  }

Print a specific BIOS field

  $wmi -with {
    {ExecQuery "select * from Win32_BIOS"}
  } -iterate bios {
    puts [$bios BiosVersion]
  }

Windows services

Print list of Windows services that are set to autostart.

  $wmi -with {
    {ExecQuery "select * from Win32_Service where StartMode='Auto'"}
  } -iterate svc {
    puts [$svc DisplayName]
  }

Network adapters

Print list of network adapters in the system.

  $wmi -with {
    {ExecQuery "select * from Win32_NetworkAdapter"}
  } -iterate net {
    puts "[$net DeviceID]:[$net Description]:[$net NetConnectionStatus]"
  }

Motherboard

Print motherboard manufacturer $wmi -with {

    {ExecQuery "select * from Win32_BaseBoard"}
  } -iterate mb {
    puts "[$mb Manufacturer] [$mb Model] [$mb Name] SN# [$mb SerialNumber]"
  }