The wmi
documentation is targeted for developers and IT administrators. You need to know where to find appropriate classes and their desired properties. The following commented script could help.
import wmi
conn = wmi.WMI() # or # wmi.WMI("some_other_machine")
# Operating system & OS version
for os in conn.Win32_OperatingSystem():
print( 'OS : ' + os.Caption + ", version " + os.Version )
# Processor name
for pr in conn.Win32_Processor():
print( 'CPU: ' + pr.Name )
# GPU model Name
# GPU Serial Number - partial solution
for vc in conn.Win32_VideoController():
print( 'GPU: ' + vc.Name + "\r\n " + vc.PNPDeviceID )
Please note that GPU Serial Number could be extracted from PNPDeviceID
only if the hardware manufacturer implements it:
Looking at the PNPDeviceID value, break it up by "\".
- The first piece it the bus type. For me, it is PCI.
- The second section describes the card. There's a vendor code, model number, etc.
- The last section contains a number separated by ampersands. The serial number is the second number in that list, formatted in hex.
Additional request: monitor details like serial Number, service tag, model name.
import wmi
conn = wmi.WMI()
# convert uint16[] array to string
def cnvrt( tup ):
return ''.join( [chr( x ) if x else '' for x in tup] )
# this is 'universal' DesktopMonitor (no useful details for Generic PnP Monitor?)
for umn in conn.Win32_DesktopMonitor():
print( 'UMn: Name {}'.format( umn.Name ) )
print( 'UMn: PNPDeviceID {}'.format( umn.PNPDeviceID ) )
# this is 'specific' DesktopMonitor (all useful details?)
con2 = wmi.WMI(namespace='root/WMI')
for mon in con2.WmiMonitorID():
print( 'Mon: Active {}'.format( mon.Active ) )
print( 'Mon: InstanceName {}'.format( mon.InstanceName ) )
print( 'Mon: ManufacturerName {}'.format( cnvrt( mon.ManufacturerName ) ) )
print( 'Mon: ProductCodeID {}'.format( cnvrt( mon.ProductCodeID ) ) )
print( 'Mon: SerialNumberID {}'.format( cnvrt( mon.SerialNumberID ) ) )
print( 'Mon: UserFriendlyName {}'.format( cnvrt( mon.UserFriendlyName ) ) )