Function lyncNotFocused {
# We need to check if the Lync window (conversation?) has focus or not.
$hwnd = [WhichWindowActive]::GetForegroundWindow()
$proc = [IntPtr]::Zero
[WhichProcessActive]::GetWindowThreadProcessId($hwnd, [ref] $proc);
Write-Host "DEBUG: Focused - hwnd $hwnd, process $proc"
if (Get-Process -ID $proc -ErrorAction "SilentlyContinue" | Where { $_ -notmatch "lync" }) { return $true }
else { return $false }
}
它返回类似“12412 True”或“9867 False”的内容。永远不要只是简单的布尔值。这些数字与我正在查找的 PID 相对应,似乎 Get-Process cmdlet 在这里大便。如何让它闭嘴?