-
Notifications
You must be signed in to change notification settings - Fork 6
/
ver_windows.go
53 lines (44 loc) · 1.02 KB
/
ver_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
package osinfo
import (
"runtime"
"strconv"
"golang.org/x/sys/windows/registry"
)
// GetVersion Windows returns version info
// fetching os info for modern windows versions is fairly simple
// version info is easily fetched in the registry
// Returns:
// - r.Runtime
// - r.Arch
// - r.Name
// - r.Version
// - r.Windows.Build
func GetVersion() Release {
info := Release{
Runtime: runtime.GOOS,
Arch: runtime.GOARCH,
Name: "unknown",
Version: "unknown",
Windows: windowsRelease{
Build: "unknown",
},
}
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
if err != nil {
return info
}
defer k.Close()
pname, _, err := k.GetStringValue("ProductName")
if err == nil {
info.Name = pname
}
ver, _, err := k.GetIntegerValue("CurrentMajorVersionNumber")
if err == nil {
info.Version = strconv.Itoa(int(ver))
}
build, _, err := k.GetStringValue("CurrentBuild")
if err == nil {
info.Windows.Build = build
}
return info
}