go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/detector/windows/build_version_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 windows 8 9 import ( 10 "runtime" 11 12 "go.mondoo.com/cnquery/providers/os/connection" 13 "go.mondoo.com/cnquery/providers/os/connection/shared" 14 "golang.org/x/sys/windows/registry" 15 ) 16 17 func GetWindowsOSBuild(conn shared.Connection) (*WindowsCurrentVersion, error) { 18 // if we are running locally on windows, we want to avoid using powershell to be faster 19 if conn.Type() == connection.Local && runtime.GOOS == "windows" { 20 k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE) 21 if err != nil { 22 return nil, err 23 } 24 25 currentBuild, _, err := k.GetStringValue("CurrentBuild") 26 if err != nil && err != registry.ErrNotExist { 27 return nil, err 28 } 29 30 ubr, _, err := k.GetIntegerValue("UBR") 31 if err != nil && err != registry.ErrNotExist { 32 return nil, err 33 } 34 35 edition, _, err := k.GetStringValue("EditionID") 36 if err != nil && err != registry.ErrNotExist { 37 return nil, err 38 } 39 defer k.Close() 40 41 return &WindowsCurrentVersion{ 42 CurrentBuild: currentBuild, 43 EditionID: edition, 44 UBR: int(ubr), 45 }, nil 46 } 47 48 // for all non-local checks use powershell 49 return powershellGetWindowsOSBuild(conn) 50 }