go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/id/platformid/win_guid_windows.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 //go:build windows 5 // +build windows 6 7 package platformid 8 9 import ( 10 "errors" 11 "runtime" 12 13 wmi "github.com/StackExchange/wmi" 14 "go.mondoo.com/cnquery/providers/os/connection" 15 "go.mondoo.com/cnquery/providers/os/connection/shared" 16 ) 17 18 func windowsMachineId(conn shared.Connection) (string, error) { 19 // if we are running locally on windows, we want to avoid using powershell to be faster 20 if conn.Type() == connection.Local && runtime.GOOS == "windows" { 21 // we always get a list or entries 22 type win32ComputerSystemProduct struct { 23 UUID *string 24 } 25 26 // query wmi to retrieve information 27 var entries []win32ComputerSystemProduct 28 if err := wmi.Query(wmiMachineIDQuery, &entries); err != nil { 29 return "", err 30 } 31 32 if len(entries) != 1 || entries[0].UUID == nil { 33 return "", errors.New("could not query machine id on windows") 34 } 35 36 return *entries[0].UUID, nil 37 } 38 39 return PowershellWindowsMachineId(conn) 40 }