github.com/lacework-dev/go-moby@v20.10.12+incompatible/pkg/parsers/operatingsystem/operatingsystem_windows.go (about) 1 package operatingsystem // import "github.com/docker/docker/pkg/parsers/operatingsystem" 2 3 import ( 4 "fmt" 5 6 "github.com/Microsoft/hcsshim/osversion" 7 "golang.org/x/sys/windows/registry" 8 ) 9 10 // GetOperatingSystem gets the name of the current operating system. 11 func GetOperatingSystem() (string, error) { 12 os, err := withCurrentVersionRegistryKey(func(key registry.Key) (os string, err error) { 13 if os, _, err = key.GetStringValue("ProductName"); err != nil { 14 return "", err 15 } 16 17 releaseId, _, err := key.GetStringValue("ReleaseId") 18 if err != nil { 19 return 20 } 21 os = fmt.Sprintf("%s Version %s", os, releaseId) 22 23 buildNumber, _, err := key.GetStringValue("CurrentBuildNumber") 24 if err != nil { 25 return 26 } 27 ubr, _, err := key.GetIntegerValue("UBR") 28 if err != nil { 29 return 30 } 31 os = fmt.Sprintf("%s (OS Build %s.%d)", os, buildNumber, ubr) 32 33 return 34 }) 35 36 if os == "" { 37 // Default return value 38 os = "Unknown Operating System" 39 } 40 41 return os, err 42 } 43 44 func withCurrentVersionRegistryKey(f func(registry.Key) (string, error)) (string, error) { 45 key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE) 46 if err != nil { 47 return "", err 48 } 49 defer key.Close() 50 return f(key) 51 } 52 53 // GetOperatingSystemVersion gets the version of the current operating system, as a string. 54 func GetOperatingSystemVersion() (string, error) { 55 version := osversion.Get() 56 return fmt.Sprintf("%d.%d.%d", version.MajorVersion, version.MinorVersion, version.Build), nil 57 } 58 59 // IsContainerized returns true if we are running inside a container. 60 // No-op on Windows, always returns false. 61 func IsContainerized() (bool, error) { 62 return false, nil 63 }