Fix Open Registry actions on non-English Windows (#11) - #12
Open
Mike-Crowley wants to merge 1 commit into
Open
Conversation
regedit.exe resolves its LastKey value against the *localized* name of the tree root node. That name comes from a string resource in regedit.exe.mui, so it is "Computer" on en-US but "Ordinateur" on fr-FR, and so on. Because every call site hard coded "Computer\", regedit silently fell back to the root node instead of navigating to the requested key on any Windows whose display language is not English. regedit also accepts a LastKey without a root node prefix and prepends the correct localized name itself, so the prefix is now stripped rather than guessed: * add Helper.NormalizeRegistryPath(), which drops a leading root node segment unless the path already starts at a hive (HKEY_*, HKLM, ...) * drop the hard coded "Computer\" from all 8 Helper.OpenRegistry() call sites in MainWindow.xaml.cs Also switch the Applets\Regedit key from OpenSubKey to CreateSubKey. The key does not exist on a profile where regedit.exe has never been started, and the null conditional SetValue silently did nothing in that case. Second part of okieselbach#11: add a "-> Device Inventory Agent folder" entry to the Open Folder menu, pointing at %ProgramW6432%\Microsoft Device Inventory Agent. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11.
Root cause
regedit.exeresolves theLastKeyvalue it reads at startup against the localized name of its tree root node. That name is a string resource inregedit.exe.mui, not a constant inregedit.exe:Every
Helper.OpenRegistry()call site hard coded the EnglishComputer\prefix. On a Windows whose display language is not English the first path segment does not match (the reporter's fr-FR machine showsOrdinateur), so regedit discards the whole path and opens at the root node instead of the requested key. That is exactly the reported symptom: "it only opens the registry but not the selected location".Verified repro
Tested on Windows 11 Enterprise 26200, en-US, by writing candidate values to
HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\LastKey, starting regedit and reading back its address bar text:LastKeywrittenComputer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ProvisioningComputer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ProvisioningOrdinateur\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ProvisioningComputerZzzz\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ProvisioningComputerHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ProvisioningComputer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ProvisioningHKLM\SOFTWARE\Microsoft\ProvisioningComputer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ProvisioningRow 2 is the mirror image of what a French user sees today, and it reproduces the bug on an English machine. Row 3 confirms the root segment really is validated. Rows 4 and 5 show the fix.
Fix
Rather than trying to detect the localized root name (it would have to be pulled out of
regedit.exe.muiby an undocumented resource id), the prefix is simply dropped. regedit accepts aLastKeywith no root node prefix and prepends the correct localized name itself, so the resulting path is language independent by construction.Helper.NormalizeRegistryPath()strips a leading root node segment unless the path already starts at a hive (HKEY_*,HKLM,HKCU, ...). Keeping it inHelpermeans a path pasted with any root name, localized or not, still resolves.Computer\from all 8Helper.OpenRegistry()call sites inMainWindow.xaml.cs, including the interpolated NodeCache path.Also switched the
Applets\Regeditkey fromOpenSubKeytoCreateSubKey. That key does not exist yet on a profile where regedit has never been started, andregistryKey?.SetValue(...)silently did nothing in that case, which is the same user visible failure.Second part of the issue
Added
-> Device Inventory Agent folderto the Open Folder menu. It uses%ProgramW6432%with a fallback toSpecialFolder.ProgramFiles, so it resolves to the nativeProgram Fileseven if the app ever runs 32-bit, and it inherits the existing "folder does not exist" message box fromHelper.OpenFolder().Testing
NormalizeRegistryPathagainst 21 cases: English and localized prefixes,My Computer, already-normalized paths, lowercase hive names, shortHKLMform, a subkey literally namedHKEY_LOCAL_MACHINE, the NodeCache path with the space inMS DM Server, plus null, empty, whitespace, leading and trailing backslashes. All pass.NormalizeRegistryPathintoLastKey, launched regedit, and confirmed via the address bar that it landed on the exact key. 7/7 pass. The NodeCache call site was verified the same way against an equivalent key shape created under HKCU, since...\NodeCache\CSP\Device\MS DM Server\Nodes\1does not exist on the test device.Clickhandler was confirmed to have a matching code-behind method.Only behaviour change for English users: none, the resulting regedit navigation is identical.
🤖 Generated with Claude Code