2023-12-09 19:25:29 +04:00
|
|
|
//go:build windows
|
|
|
|
// +build windows
|
|
|
|
|
2023-10-30 02:18:41 +04:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"golang.org/x/sys/windows/registry"
|
|
|
|
)
|
|
|
|
|
|
|
|
func OSVersion() (string, error) {
|
|
|
|
switch osName := runtime.GOOS; osName {
|
|
|
|
case "windows":
|
|
|
|
verKey, err := registry.OpenKey(registry.LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion", registry.QUERY_VALUE)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
major, _, err := verKey.GetIntegerValue("CurrentMajorVersionNumber")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
minor, _, err := verKey.GetIntegerValue("CurrentMinorVersionNumber")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%d.%d", major, minor), nil
|
|
|
|
}
|
|
|
|
return "", errors.New("unknown OS")
|
|
|
|
}
|