Skip to content

Conversation

Copy link

Copilot AI commented Jan 27, 2026

When regedit is launched for the first time, Process.Start() returns before the window hierarchy is fully initialized. The code attempted to send navigation messages to window handles that were still IntPtr.Zero, causing silent failure.

Changes

  • Add retry logic for main window handle acquisition: After process start, poll MainWindowHandle with Refresh() for up to 5s (50×100ms)
  • Add retry logic for child control discovery: Poll FindWindowEx() for tree/list views for up to 5s before sending navigation messages
  • Extract retry constants: MAX_WINDOW_WAIT_RETRIES and MAX_CHILD_WINDOW_WAIT_RETRIES for maintainability
// Before: Immediate access, often IntPtr.Zero
process = Process.Start("regedit.exe", "-m");
process.WaitForInputIdle();
hMain = process.MainWindowHandle;  // May be Zero

// After: Wait for handle availability
process = Process.Start("regedit.exe", "-m");
process.WaitForInputIdle();
int retries = MAX_WINDOW_WAIT_RETRIES;
while (retries-- > 0) {
    process.Refresh();
    hMain = process.MainWindowHandle;
    if (hMain != IntPtr.Zero) break;
    Thread.Sleep(100);
}
if (hMain == IntPtr.Zero) return;

This also fixes the case where regedit is already open but window handles become stale between calls.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: 注册表无法定位到具体值</issue_title>
<issue_description>### Checklist

  • This bug has not already been reported (search here)
  • I have updated ContextMenuManager to the latest version
  • I understand that any issue not following the guidelines may be closed directly

Windows

Windows 11

Version

3.6.2.0

Steps to Reproduce

Video_2026-01-27_000444.mp4

复现方法:
已上传视频为附件,首先不要运行regedit,如果运行着的要关闭掉,随便一项,点击齿轮,在弹出菜单中点击【详细信息-注册表位置】。此时只打开了regedit,并不会定位到对应的注册表值。
保留regedit窗口,再次点击【注册表位置】,此时才能定位到对应的注册表值。

我不知道为什么会这样,测试了两台机器,依旧如此。老版的3.3.3.1也有同样的问题。

Crash logs

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix registry not locating specific values in Windows 11 Fix race condition in registry editor navigation on first launch Jan 27, 2026
Copilot AI requested a review from Jack251970 January 27, 2026 05:23
@Jack251970 Jack251970 closed this Jan 27, 2026
@Jack251970 Jack251970 deleted the copilot/fix-registry-location-bug branch January 27, 2026 16:29
@Jack251970 Jack251970 restored the copilot/fix-registry-location-bug branch January 28, 2026 06:52
@Jack251970 Jack251970 reopened this Jan 28, 2026
@Jack251970 Jack251970 marked this pull request as ready for review January 28, 2026 06:54
Copilot AI review requested due to automatic review settings January 28, 2026 06:54
@Jack251970 Jack251970 merged commit 169d53e into master Jan 28, 2026
5 checks passed
@Jack251970 Jack251970 deleted the copilot/fix-registry-location-bug branch January 28, 2026 06:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a race condition that occurs when launching the Windows Registry Editor (regedit) for the first time. The issue occurred because Process.Start() returns before the window hierarchy is fully initialized, causing attempts to send navigation messages to window handles that were still IntPtr.Zero, resulting in silent failure.

Changes:

  • Added retry logic with polling for main window handle acquisition (up to 5 seconds with 50 retries × 100ms each)
  • Added retry logic with polling for child control discovery (tree view and list view controls, also up to 5 seconds)
  • Extracted retry constants MAX_WINDOW_WAIT_RETRIES and MAX_CHILD_WINDOW_WAIT_RETRIES for better maintainability

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

[Bug]: 注册表无法定位到具体值

2 participants