github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/pkg/parsers/operatingsystem/operatingsystem_windows.go (about) 1 package operatingsystem // import "github.com/Prakhar-Agarwal-byte/moby/pkg/parsers/operatingsystem" 2 3 import ( 4 "errors" 5 6 "github.com/Microsoft/hcsshim/osversion" 7 "golang.org/x/sys/windows" 8 "golang.org/x/sys/windows/registry" 9 ) 10 11 // VER_NT_WORKSTATION, see https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfoexa 12 const verNTWorkstation = 0x00000001 // VER_NT_WORKSTATION 13 14 // GetOperatingSystem gets the name of the current operating system. 15 func GetOperatingSystem() (string, error) { 16 osversion := windows.RtlGetVersion() // Always succeeds. 17 rel := windowsOSRelease{ 18 IsServer: osversion.ProductType != verNTWorkstation, 19 Build: osversion.BuildNumber, 20 } 21 22 // Make a best-effort attempt to retrieve the display version and 23 // Update Build Revision by querying undocumented registry values. 24 key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE) 25 if err == nil { 26 defer key.Close() 27 if ver, err := getFirstStringValue(key, 28 "DisplayVersion", /* Windows 20H2 and above */ 29 "ReleaseId", /* Windows 2009 and below */ 30 ); err == nil { 31 rel.DisplayVersion = ver 32 } 33 if ubr, _, err := key.GetIntegerValue("UBR"); err == nil { 34 rel.UBR = ubr 35 } 36 } 37 38 return rel.String(), nil 39 } 40 41 func getFirstStringValue(key registry.Key, names ...string) (string, error) { 42 for _, n := range names { 43 val, _, err := key.GetStringValue(n) 44 if err != nil { 45 if !errors.Is(err, registry.ErrNotExist) { 46 return "", err 47 } 48 continue 49 } 50 return val, nil 51 } 52 return "", registry.ErrNotExist 53 } 54 55 // GetOperatingSystemVersion gets the version of the current operating system, as a string. 56 func GetOperatingSystemVersion() (string, error) { 57 return osversion.Get().ToString(), nil 58 } 59 60 // IsContainerized returns true if we are running inside a container. 61 // No-op on Windows, always returns false. 62 func IsContainerized() (bool, error) { 63 return false, nil 64 } 65 66 // IsWindowsClient returns true if the SKU is client. It returns false on 67 // Windows server. 68 func IsWindowsClient() bool { 69 return windows.RtlGetVersion().ProductType == verNTWorkstation 70 }