MCPcopy
hub / github.com/kubernetes/node-problem-detector / GetOSVersion

Function GetOSVersion

pkg/util/helpers_windows.go:38–58  ·  view source on GitHub ↗

GetOSVersion retrieves the version of the current operating system. For example: "windows 10.0.17763.1697 (Windows Server 2016 Datacenter)".

()

Source from the content-addressed store, hash-verified

36// GetOSVersion retrieves the version of the current operating system.
37// For example: "windows 10.0.17763.1697 (Windows Server 2016 Datacenter)".
38func GetOSVersion() (string, error) {
39 k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
40 if err != nil {
41 return "", err
42 }
43 defer k.Close()
44
45 productName, _, err := k.GetStringValue("ProductName")
46 if err != nil {
47 productName = "windows"
48 }
49
50 ubr, _, err := k.GetIntegerValue("UBR")
51 if err != nil {
52 ubr = 0
53 }
54
55 major, minor, build := windows.RtlGetNtVersionNumbers()
56
57 return fmt.Sprintf("windows %d.%d.%d.%d (%s)", major, minor, build, ubr, productName), nil
58}

Callers 1

NewHostCollectorOrDieFunction · 0.92

Calls 1

CloseMethod · 0.65

Tested by

no test coverage detected