2019年了,Go标准库中的syscall.GetVersion还在使用GetVersion….
不多说贴代码
package main
import (
"fmt"
"syscall"
"unsafe"
)
func main() {
var dwMajorVer int
var dwMinorVer int
var dwBuildNumber int
ntdll := syscall.NewLazyDLL("ntdll.dll")
RtlGetNtVersionNumbers := ntdll.NewProc("RtlGetNtVersionNumbers")
RtlGetNtVersionNumbers.Call(uintptr(unsafe.Pointer(&dwMajorVer)), uintptr(unsafe.Pointer(&dwMinorVer)), uintptr(unsafe.Pointer(&dwBuildNumber)))
dwBuildNumber = dwBuildNumber & 0xffff
fmt.Println(dwMajorVer,dwMinorVer,dwBuildNumber)
}
//不支持xp以下的系统(不包括xp)
package main
import (
"fmt"
"syscall"
"unsafe"
)
type SystemInfo struct {
ProcessorArchitecture uint16
Reserved uint16
PageSize uint32
MinimumApplicationAddress uintptr
MaximumApplicationAddress uintptr
ActiveProcessorMask uint64
NumberOfProcessors uint32
ProcessorType uint32
AllocationGranularity uint32
ProcessorLevel uint16
ProcessorRevision uint16
}
func main() {
kernel32 := syscall.NewLazyDLL("kernel32.dll")
GetNativeSystemInfo:=kernel32.NewProc("GetNativeSystemInfo")
a:=new(SystemInfo)
GetNativeSystemInfo.Call(uintptr(unsafe.Pointer(a)))
if a.ProcessorArchitecture==9 {
fmt.Println(64)
}else {
fmt.Println(32)
}
}
声明:
本文采用
BY-NC-SA
协议进行授权,如无注明均为原创,转载请注明转自
xxs的博客
本文地址: Go获取win8以上系统版本号,位数
本文地址: Go获取win8以上系统版本号,位数