-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosdetector_windows.go
55 lines (45 loc) · 1.15 KB
/
osdetector_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package osdetector
import (
"fmt"
"golang.org/x/sys/windows/registry"
)
// source: https://stackoverflow.com/questions/44363911/detect-windows-version-in-go
func (osd *OsDetector) GetWindowsDistro() (*Distro, error) {
result := &Distro{
Os: "Windows",
BasedOn: "Windows NT",
Dist: "Windows",
PseudoName: "",
}
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
if err != nil {
return nil, err
}
defer k.Close()
//cv, _, err := k.GetStringValue("CurrentVersion")
//if err != nil {
// return nil, err
//}
//fmt.Printf("CurrentVersion: %s\n", cv)
pn , _, err := k.GetStringValue("ProductName")
if err != nil {
return nil, err
}
result.PseudoName = pn
maj, _, err := k.GetIntegerValue("CurrentMajorVersionNumber")
if err != nil {
return nil, err
}
result.Rev = fmt.Sprintf("%d.", maj)
min, _, err := k.GetIntegerValue("CurrentMinorVersionNumber")
if err != nil {
return nil, err
}
result.Rev += fmt.Sprintf("%d.", min)
cb, _, err := k.GetStringValue("CurrentBuild")
if err != nil {
return nil, err
}
result.Rev += cb
return result, nil
}