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
This commit is contained in:
Berrick Werkman 2024-05-11 15:52:52 -05:00 committed by GitHub
parent 15eb12af11
commit f130fc6c49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)"
}
}