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)
	}
}
说点什么
支持Markdown语法
好耶,沙发还空着ヾ(≧▽≦*)o
Loading...