From f130fc6c495e87e6559f4b1b3dbb5c61139a2c56 Mon Sep 17 00:00:00 2001 From: Berrick Werkman <105836264+BKlaasWerkman@users.noreply.github.com> Date: Sat, 11 May 2024 15:52:52 -0500 Subject: [PATCH] Main window handle (#1941) Condition is comparing $proc.Id with [System.IntPtr]::Zero. The Id property is an integer, representing the process ID, and it's not directly related to window handles. Instead, you should compare the MainWindowHandle property against [System.IntPtr]::Zero --- scripts/main.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index cc9aaa35..5507d641 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -271,10 +271,14 @@ Add-Type @" "@ } - foreach ($proc in (Get-Process | Where-Object { $_.MainWindowTitle -and $_.MainWindowTitle -like "*titus*" })) { - if ($proc.Id -ne [System.IntPtr]::Zero) { + foreach ($proc in (Get-Process | Where-Object { $_.MainWindowTitle -and $_.MainWindowTitle -like "*titus*" })) { + # Check if the process's MainWindowHandle is valid + if ($proc.MainWindowHandle -ne [System.IntPtr]::Zero) { Write-Debug "MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle) $($proc.MainWindowHandle)" $windowHandle = $proc.MainWindowHandle + } else { + Write-Warning "Process found, but no MainWindowHandle: $($proc.Id) $($proc.MainWindowTitle)" + } }