Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Powershell关闭IE中的活动选项卡_C#_Powershell_Internet Explorer - Fatal编程技术网

C# 使用Powershell关闭IE中的活动选项卡

C# 使用Powershell关闭IE中的活动选项卡,c#,powershell,internet-explorer,C#,Powershell,Internet Explorer,有人知道如何使用powershell关闭internet explorer的活动选项卡吗 我希望这样只关闭选项卡(而不是窗口中的所有选项卡) 如有任何意见,将不胜感激 我已经试过了 $ie = (New-Object -COM "Shell.Application").Windows() | ? { $_.Name -eq "Internet Explorer" } $ie.Quit() 但是,这会关闭所有选项卡$ie包含所有打开的选项卡的数组,因此当您调用Quit()时,它会关闭所有打开的选

有人知道如何使用powershell关闭internet explorer的活动选项卡吗

我希望这样只关闭选项卡(而不是窗口中的所有选项卡)

如有任何意见,将不胜感激

我已经试过了

$ie = (New-Object -COM "Shell.Application").Windows() | ? { $_.Name -eq "Internet Explorer" }
$ie.Quit()

但是,这会关闭所有选项卡

$ie
包含所有打开的选项卡的数组,因此当您调用
Quit()
时,它会关闭所有打开的选项卡

如果指定所需的选项卡,它应该可以工作

要关闭最后一个选项卡,请执行以下操作:

$ie[-1].Quit()
要关闭第一个选项卡,请执行以下操作:

$ie[1].Quit()
要关闭特定URL的选项卡,请执行以下操作:

$ie.Where({ $_.LocationURL -eq "https://stackoverflow.com/" }).Quit()
查找活动选项卡的最简单方法是
Get Process
中的
MainWindowTitle
属性,该属性应大致与其中一个选项卡的
LocationName
匹配

$ie = (New-Object -COM "Shell.Application").Windows() | ? { $_.Name -eq "Internet Explorer" }
$activeTab = ((Get-Process IExplore).MainWindowTitle | ? { $_ -ne "" }) -replace " - Internet Explorer"
$ie.Where({ $_.LocationName -eq $activeTab }).Quit()
注意:这将关闭Internet Explorer中的所有活动选项卡,浏览器的每个实例将有一个活动选项卡。如果这是一个问题,那么您需要隔离要关闭activeTab的Internet Explorer实例,每个实例都应该有一个唯一的
HWND