
$notToKill.Add( $windowPid, ( $string.ToString() ) ) ) # keep a list of innocent pids so we can warn if we are going to kill them Write-Verbose "Not killing pid $windowPid with text `"$($string.ToString())`" as no match" # already have it so don't try and kill twice $toKill.Add( $windowPid, Title = $string.tostring() 'Process' = $ieProcess } )
Sysfader error internet explorer 8 windows#
# Can't kill processes yet as it can mess up fetching of windows Write-Verbose "Will kill pid $windowPid with text `"$($string.ToString())`"" If( $string.ToString() -match $URLtoKill ) If( (Get-Process -Id $ieProcess.ParentProcessId -ErrorAction Silentl圜ontinue | Select-Object -ExpandProperty Name) -eq 'iexplore') # only look to kill if it is a child process not the parent as that will kill everything but still count the tab for reporting/checking purposes If( $string.tostring() -notmatch '^(MSCTFIME UI|Default IME|SysFader|MCI command handling window|Tooltip|DDE Server Window|PseudoServerHiddenWindow|Blank Page - Internet Explorer)$' ) # can be hidden blank pages but ignore anyway since won't contain content If( ::GetWindowText( $window, $string, ( $length + 1 )) -gt 0 ) $length = ::GetWindowTextLength( $window ) (::GetWindowThreadProcessId( $window, $windowPid )) Write-Error "Failed to get top most window in session $sessionId so cannot get tabs" Write-Warning "No child iexplore.exe processes found in session $sessionid" $notToKill = ! $ieProcesses -or ! $ieProcesses.Count ) $ieProcesses.Add( $_.ProcessId -as, $_ ) Get-CimInstance -Class Win32_Process -Filter "Name = 'iexplore.exe' and SessionId = '$sessionId'" | ForEach-Object ` # command line not returned on Server 2016 when run as non-admin - we will check later that it's a child of another IE process otherwise likely to kill multiple tabs $ieProcesses = Altering the size of the PS Buffer Write-Warning "Failed to get owner for process id $($process.ProcessId) ($($process.Name))"

Join-Path -Path 'HKU:\' -ChildPath $sid # return (New-PSDrive -Name HKU -PSProvider Registry -Root 'Registry::HKEY_USERS' -Scope Script ) If( ! ( Get-PSdrive -Name HKU -ErrorAction Silentl圜ontinue ) ) Write-Warning "Failed to get sid for user $($owner.Domain)\$($owner.User))"

$sid = (New-Object -TypeName ( "$($owner.Domain)\$($owner.User)" )).Translate().Value $owner = Invoke-CimMethod -InputObject $process -MethodName GetOwner

Public static extern int GetWindowTextLength(IntPtr Get-HKCU Public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount) Public static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd) Public static extern IntPtr GetTopWindow(IntPtr hWnd) Public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId) $killRegardless = ( $args.Count -ge 4 -and ( $args -eq 'Yes' -or $args -match 'True' ))Īdd-Type -Namespace User32 -Name Util -UsingNamespace System.Text -MemberDefinition SetLastError=true)] $forceKill = ( $args.Count -ge 3 -and ( $args -eq 'Yes' -or $args -match 'True' )) Throw 'Must pass the URL to kill on the command line' $URLtoKill = if( $args.Count -ge 2 -and $args ) Throw 'Must pass the session id of the session on the command line' $sessionId = if( $args.Count -and $args ) Copy Script Copied to clipboard #requires -version 3
