//go:build windows // Package collector 实现 Windows 系统静态信息采集。 // Logan.Li package collector import ( "os/exec" "strings" ) type SystemInfo struct { OSVersion string Kernel string UptimeSeconds int64 } func CollectSystem() SystemInfo { return SystemInfo{ OSVersion: windowsOSCaption(), Kernel: windowsVersion(), UptimeSeconds: windowsUptime(), } } func windowsOSCaption() string { out, err := exec.Command("powershell.exe", "-NoProfile", "-Command", "(Get-CimInstance Win32_OperatingSystem).Caption").Output() if err != nil { return "Windows" } if s := strings.TrimSpace(string(out)); s != "" { return s } return "Windows" } func windowsVersion() string { out, err := exec.Command("cmd.exe", "/C", "ver").Output() if err != nil { return "" } return strings.TrimSpace(string(out)) } func windowsUptime() int64 { out, err := exec.Command("powershell.exe", "-NoProfile", "-Command", "[int]((Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime).TotalSeconds").Output() if err != nil { return 0 } var n int64 for _, ch := range strings.TrimSpace(string(out)) { if ch >= '0' && ch <= '9' { n = n*10 + int64(ch-'0') } } return n }