Skip to content

Guard MSI UpgradeCode lookup against missing registry key#1

Closed
Tom Plant (pl4nty) wants to merge 1 commit into
mainfrom
claude/registry-path-not-found-c51i5e
Closed

Guard MSI UpgradeCode lookup against missing registry key#1
Tom Plant (pl4nty) wants to merge 1 commit into
mainfrom
claude/registry-path-not-found-c51i5e

Conversation

@pl4nty

Copy link
Copy Markdown
Member

Description

Get-ADTApplication's begin block builds an MSI UpgradeCode lookup table with an unguarded Get-ChildItem on HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes. On machines where that key does not exist (e.g. clean images / Windows Sandbox with no MSI-registered upgrade codes), Get-ChildItem throws:

Cannot find path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes' because it does not exist.
FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Because this happens in the begin block, it aborts the entire function and every caller — including Uninstall-ADTApplication, as seen in the reported stack trace.

The fix adds -ErrorAction Ignore to that Get-ChildItem, matching the pattern already used a few lines down for the uninstall-key enumeration. When the key is absent the pipeline yields no items, the scriptblock's begin/end blocks still run, and $msiUpgradeCodeLookupTable is simply an empty dictionary. Downstream indexing ($msiUpgradeCodeLookupTable[$appMsiGuid]) already returns $null for GUIDs that are not present, so behaviour is unchanged for the common case and no longer throws for the empty case.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • General code cleanup (non-breaking change which improves readability)

Checklist

  • I am pulling to the main branch
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have tested my changes to prove my fix is effective
  • I have tested that the module can build following my changes
  • I have made sure that any script file-encoding is set to UTF8 with BOM, i.e. unchanged.

How Has This Been Tested?

Not yet run against a live host — pwsh is unavailable in the CI/dev environment used here. The change is a single-parameter addition consistent with the existing -ErrorAction Ignore usage in the same function. Recommended verification: on a machine lacking the Installer\UpgradeCodes registry key, confirm Get-ADTApplication (and Uninstall-ADTApplication) now complete without a PathNotFound error and still return installed applications.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XLNM98Nd3HZLTWFatRVgB1


Generated by Claude Code

Get-ADTApplication built its MSI UpgradeCode lookup table with an
unguarded Get-ChildItem on
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes.
On machines where that key does not exist (e.g. images with no
MSI-registered upgrade codes), Get-ChildItem threw a PathNotFound
error that aborted the function's begin block, breaking any caller
such as Uninstall-ADTApplication.

Add -ErrorAction Ignore to match the pattern already used for the
uninstall key enumeration. When the key is absent the pipeline yields
no items, the scriptblock's begin/end blocks still run, and the
lookup table is simply empty; downstream indexing already returns
$null for GUIDs that are not present.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XLNM98Nd3HZLTWFatRVgB1
@mjr4077au

Copy link
Copy Markdown
Member

Thanks mate, didn't even consider the possibility of this when I put this in a few weeks ago!

@pl4nty Tom Plant (pl4nty) deleted the claude/registry-path-not-found-c51i5e branch July 4, 2026 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants