github.com/jaypipes/ghw@v0.21.1/pkg/product/product_windows.go (about)

     1  // Use and distribution licensed under the Apache license version 2.
     2  //
     3  // See the COPYING file in the root project directory for full text.
     4  //
     5  
     6  package product
     7  
     8  import (
     9  	"github.com/yusufpapurcu/wmi"
    10  
    11  	"github.com/jaypipes/ghw/pkg/util"
    12  )
    13  
    14  const wqlProduct = "SELECT Caption, Description, IdentifyingNumber, Name, SKUNumber, Vendor, Version, UUID FROM Win32_ComputerSystemProduct"
    15  
    16  type win32Product struct {
    17  	Caption           *string
    18  	Description       *string
    19  	IdentifyingNumber *string
    20  	Name              *string
    21  	SKUNumber         *string
    22  	Vendor            *string
    23  	Version           *string
    24  	UUID              *string
    25  }
    26  
    27  func (i *Info) load() error {
    28  	// Getting data from WMI
    29  	var win32ProductDescriptions []win32Product
    30  	// Assuming the first product is the host...
    31  	if err := wmi.Query(wqlProduct, &win32ProductDescriptions); err != nil {
    32  		return err
    33  	}
    34  	if len(win32ProductDescriptions) > 0 {
    35  		i.Family = util.UNKNOWN
    36  		i.Name = *win32ProductDescriptions[0].Name
    37  		i.Vendor = *win32ProductDescriptions[0].Vendor
    38  		i.SerialNumber = *win32ProductDescriptions[0].IdentifyingNumber
    39  		i.UUID = *win32ProductDescriptions[0].UUID
    40  		i.SKU = *win32ProductDescriptions[0].SKUNumber
    41  		i.Version = *win32ProductDescriptions[0].Version
    42  	}
    43  
    44  	return nil
    45  }