From 4fea8cad0465ef9e25d7df442ecb73f8098943bf Mon Sep 17 00:00:00 2001 From: Christian Zunker Date: Wed, 20 Nov 2024 16:33:08 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20Windows=20platform=20detec?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When running locally, collect all the data we need. Signed-off-by: Christian Zunker --- .../detector/windows/build_version_windows.go | 50 +++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/providers/os/detector/windows/build_version_windows.go b/providers/os/detector/windows/build_version_windows.go index 1c70424f5e..62c148dee3 100644 --- a/providers/os/detector/windows/build_version_windows.go +++ b/providers/os/detector/windows/build_version_windows.go @@ -20,6 +20,7 @@ func GetWindowsOSBuild(conn shared.Connection) (*WindowsCurrentVersion, error) { if err != nil { return nil, err } + defer k.Close() currentBuild, _, err := k.GetStringValue("CurrentBuild") if err != nil && err != registry.ErrNotExist { @@ -35,12 +36,53 @@ func GetWindowsOSBuild(conn shared.Connection) (*WindowsCurrentVersion, error) { if err != nil && err != registry.ErrNotExist { return nil, err } - defer k.Close() + + displayVersion, _, err := k.GetStringValue("DisplayVersion") + if err != nil && err != registry.ErrNotExist { + return nil, err + } + + title, _, err := k.GetStringValue("ProductName") + if err != nil && err != registry.ErrNotExist { + return nil, err + } + + installationType, _, err := k.GetStringValue("InstallationType") + if err != nil && err != registry.ErrNotExist { + return nil, err + } + + systemKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control\ProductOptions`, registry.QUERY_VALUE) + if err != nil { + return nil, err + } + defer systemKey.Close() + + productType, _, err := systemKey.GetStringValue("ProductType") + if err != nil && err != registry.ErrNotExist { + return nil, err + } + + envKey, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control\Session Manager\Environment`, registry.QUERY_VALUE) + if err != nil { + return nil, err + } + defer envKey.Close() + + arch, _, err := envKey.GetStringValue("PROCESSOR_ARCHITECTURE") + if err != nil && err != registry.ErrNotExist { + return nil, err + } return &WindowsCurrentVersion{ - CurrentBuild: currentBuild, - EditionID: edition, - UBR: int(ubr), + CurrentBuild: currentBuild, + EditionID: edition, + UBR: int(ubr), + Architecture: arch, + DisplayVersion: displayVersion, + ProductName: title, + ProductType: productType, + InstallationType: installationType, }, nil }