Skip to content

Commit 21271db

Browse files
committed
Improve single instance checks
1 parent 3bd31f6 commit 21271db

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

ProcessHacker/main.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ static BOOLEAN NTAPI PhpPreviousInstancesCallback(
427427
HANDLE processHandle = NULL;
428428
HANDLE tokenHandle = NULL;
429429
PTOKEN_USER tokenUser = NULL;
430+
ULONG attempts = 50;
430431

431432
if (objectInfo.ClientId.UniqueProcess == NtCurrentProcessId())
432433
goto CleanupExit;
@@ -439,11 +440,20 @@ static BOOLEAN NTAPI PhpPreviousInstancesCallback(
439440
if (!RtlEqualSid(tokenUser->User.Sid, PhGetOwnTokenAttributes().TokenSid))
440441
goto CleanupExit;
441442

442-
hwnd = PhGetProcessMainWindowEx(
443-
objectInfo.ClientId.UniqueProcess,
444-
processHandle,
445-
FALSE
446-
);
443+
// Try to locate the window a few times because some users reported issues that it might not yet have been created. (dmex)
444+
do
445+
{
446+
if (hwnd = PhGetProcessMainWindowEx(
447+
objectInfo.ClientId.UniqueProcess,
448+
processHandle,
449+
FALSE
450+
))
451+
{
452+
break;
453+
}
454+
455+
PhDelayExecution(100);
456+
} while (--attempts != 0);
447457

448458
if (hwnd)
449459
{

0 commit comments

Comments
 (0)