-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_windows.go
44 lines (36 loc) · 1.12 KB
/
main_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package osversion
import (
"unsafe"
"golang.org/x/sys/windows"
)
// http://yamatyuu.net/computer/program/sdk/base/RtlGetVersion/index.html
var ntdll = windows.NewLazySystemDLL("ntdll.dll")
var procRtlGetVersion = ntdll.NewProc("RtlGetVersion")
type _OSVERSIONINFOEXW struct {
dwOSVersionInfoSize uint32
dwMajorVersion uint32
dwMinorVersion uint32
dwBuildNumber uint32
dwPlatformId uint32
szCSDVersion [128]uint16
wServicePackMajor uint16
wServicePackMinor uint16
wSuiteMask uint16
wProductType uint8
wReserved uint8
}
func query() *Version {
var buffer _OSVERSIONINFOEXW
buffer.dwOSVersionInfoSize = uint32(unsafe.Sizeof(buffer))
procRtlGetVersion.Call(uintptr(unsafe.Pointer(&buffer)))
// _OSVERSIONINFOEXW is too large to return.
// So, copy some member to smaller struct.
return &Version{
Major: buffer.dwMajorVersion,
Minor: buffer.dwMinorVersion,
Build: buffer.dwBuildNumber,
PlatformId: buffer.dwPlatformId,
ServicePackMajor: buffer.wServicePackMajor,
ServicePackMinor: buffer.wServicePackMinor,
}
}