返回 DeepSeek-Reasonix
devinfo_windows.go
根目录 / desktop / devinfo_windows.go
1 package main
2
3 import (
4 "fmt"
5 "strings"
6 "unsafe"
7
8 "golang.org/x/sys/windows"
9 "golang.org/x/sys/windows/registry"
10 )
11
12 func platformOSVersion() string {
13 v := windows.RtlGetVersion()
14 return fmt.Sprintf("Windows %d.%d build %d", v.MajorVersion, v.MinorVersion, v.BuildNumber)
15 }
16
17 func platformOSBuild() (int, int) {
18 v := windows.RtlGetVersion()
19 revision := 0
20 if k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE); err == nil {
21 defer k.Close()
22 if ubr, _, readErr := k.GetIntegerValue("UBR"); readErr == nil {
23 revision = int(ubr)
24 }
25 }
26 return int(v.BuildNumber), revision
27 }
28
29 func platformEnvironmentInfo() platformEnvironment { return platformEnvironment{} }
30
31 func platformCPU() string {
32 k, err := registry.OpenKey(registry.LOCAL_MACHINE, `HARDWARE\DESCRIPTION\System\CentralProcessor\0`, registry.QUERY_VALUE)
33 if err != nil {
34 return ""
35 }
36 defer k.Close()
37 name, _, err := k.GetStringValue("ProcessorNameString")
38 if err != nil {
39 return ""
40 }
41 return strings.TrimSpace(name)
42 }
43
44 func platformRAMBytes() uint64 {
45 var kb uint64
46 proc := windows.NewLazySystemDLL("kernel32.dll").NewProc("GetPhysicallyInstalledSystemMemory")
47 if ret, _, _ := proc.Call(uintptr(unsafe.Pointer(&kb))); ret == 0 {
48 return 0
49 }
50 return kb * 1024
51 }
52
52 lines GO