Skip to content

Instantly share code, notes, and snippets.

@hihigash
Created April 17, 2020 14:32
Show Gist options
  • Select an option

  • Save hihigash/84973f0fa06bfa686cb879cdaeecaf70 to your computer and use it in GitHub Desktop.

Select an option

Save hihigash/84973f0fa06bfa686cb879cdaeecaf70 to your computer and use it in GitHub Desktop.
$code = @'
[DllImport("user32.dll")]
public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out int ProcessId);
'@
Add-Type $code -Name Utils -Namespace Win32
Function GetProcessIdByHWND($whnd) {
[IntPtr]$result = [IntPtr]::Zero
[Win32.Utils]::GetWindowThreadProcessId([Int32]$whnd, [ref]$result)
return $result
}
$shell = New-Object -ComObject Shell.Application
$ie_list = $shell.Windows() | Select-Object HWND, LocationName, LocationURL, @{Name = "Id"; Expression = { @(GetProcessIdByHWND($_.HWND)) } }
Get-Process -IncludeUserName | Where-Object { $_.CPU -gt 90 -and $_.ProcessName -eq "iexplore" } | ForEach-Object {
$process = $_
Write-Output "CPU:$($_.CPU)`t$($_.UserName) ($($_.Id))"
Write-Output ------
$ie_list | Where-Object { $_.Id -eq $process.Id } | ForEach-Object {
Write-Output "$($_.LocationName) ($($_.LocationURL))"
}
Write-Output ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment