diff --git a/.changelog/201.txt b/.changelog/201.txt new file mode 100644 index 0000000..dcd5737 --- /dev/null +++ b/.changelog/201.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +HostInfo.NativeArchitecture is not available on Windows system prior Windows 10 version 1709. +``` \ No newline at end of file diff --git a/providers/windows/arch_windows.go b/providers/windows/arch_windows.go index fc4b9a9..6a889a0 100644 --- a/providers/windows/arch_windows.go +++ b/providers/windows/arch_windows.go @@ -18,6 +18,8 @@ package windows import ( + "errors" + "golang.org/x/sys/windows" gowindows "github.com/elastic/go-windows" @@ -44,8 +46,17 @@ func NativeArchitecture() (string, error) { // the pseudo handle doesn't need to be closed var currentProcessHandle = windows.CurrentProcess() + // IsWow64Process2 was introduced in version 1709 (build 16299 acording to the tables) + // https://learn.microsoft.com/en-us/windows/release-health/release-information + // https://learn.microsoft.com/en-us/windows/release-health/windows-server-release-info err := windows.IsWow64Process2(currentProcessHandle, &processMachine, &nativeMachine) if err != nil { + if errors.Is(err, windows.ERROR_PROC_NOT_FOUND) { + major, minor, build := windows.RtlGetNtVersionNumbers() + if major < 10 || (major == 10 && minor == 0 && build < 16299) { + return "", nil + } + } return "", err }