Skip to content

Commit

Permalink
🐛 Fix Windows platform detection (#4902)
Browse files Browse the repository at this point in the history
When running locally, collect all the data we need.

Signed-off-by: Christian Zunker <[email protected]>
  • Loading branch information
czunker authored Nov 20, 2024
1 parent bf654ad commit c10e069
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions providers/os/detector/windows/build_version_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down

0 comments on commit c10e069

Please sign in to comment.