Merge pull request #1147 from elmeyer/fix-windows-11

host, v3/host (Windows): Fix Windows 11 reporting
This commit is contained in:
shirou 2021-10-09 22:45:58 +09:00 committed by GitHub
commit 27a7c1c06b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"context" "context"
"fmt" "fmt"
"math" "math"
"strconv"
"strings" "strings"
"sync/atomic" "sync/atomic"
"syscall" "syscall"
@ -161,6 +162,19 @@ func PlatformInformationWithContext(ctx context.Context) (platform string, famil
return return
} }
platform = windows.UTF16ToString(regBuf[:]) platform = windows.UTF16ToString(regBuf[:])
if strings.Contains(platform, "Windows 10") { // check build number to determine whether it's actually Windows 11
err = windows.RegQueryValueEx(h, windows.StringToUTF16Ptr(`CurrentBuildNumber`), nil, &valType, nil, &bufLen)
if err == nil {
regBuf = make([]uint16, bufLen/2+1)
err = windows.RegQueryValueEx(h, windows.StringToUTF16Ptr(`CurrentBuildNumber`), nil, &valType, (*byte)(unsafe.Pointer(&regBuf[0])), &bufLen)
if err == nil {
buildNumberStr := windows.UTF16ToString(regBuf[:])
if buildNumber, err := strconv.Atoi(buildNumberStr); err == nil && buildNumber >= 22000 {
platform = strings.Replace(platform, "Windows 10", "Windows 11", 1)
}
}
}
}
if !strings.HasPrefix(platform, "Microsoft") { if !strings.HasPrefix(platform, "Microsoft") {
platform = "Microsoft " + platform platform = "Microsoft " + platform
} }

View File

@ -6,6 +6,7 @@ import (
"context" "context"
"fmt" "fmt"
"math" "math"
"strconv"
"strings" "strings"
"sync/atomic" "sync/atomic"
"syscall" "syscall"
@ -161,6 +162,19 @@ func PlatformInformationWithContext(ctx context.Context) (platform string, famil
return return
} }
platform = windows.UTF16ToString(regBuf[:]) platform = windows.UTF16ToString(regBuf[:])
if strings.Contains(platform, "Windows 10") { // check build number to determine whether it's actually Windows 11
err = windows.RegQueryValueEx(h, windows.StringToUTF16Ptr(`CurrentBuildNumber`), nil, &valType, nil, &bufLen)
if err == nil {
regBuf = make([]uint16, bufLen/2+1)
err = windows.RegQueryValueEx(h, windows.StringToUTF16Ptr(`CurrentBuildNumber`), nil, &valType, (*byte)(unsafe.Pointer(&regBuf[0])), &bufLen)
if err == nil {
buildNumberStr := windows.UTF16ToString(regBuf[:])
if buildNumber, err := strconv.Atoi(buildNumberStr); err == nil && buildNumber >= 22000 {
platform = strings.Replace(platform, "Windows 10", "Windows 11", 1)
}
}
}
}
if !strings.HasPrefix(platform, "Microsoft") { if !strings.HasPrefix(platform, "Microsoft") {
platform = "Microsoft " + platform platform = "Microsoft " + platform
} }