
使用 Windows 7 和 Internet Explorer 9(或更高版本),我嘗試建立特定網頁的桌面捷徑。訣竅是,如果使用者已經在任何 IE 視窗中開啟該網頁,我需要捷徑來聚焦到該窗口,而不是建立一個新視窗。
答案1
此 powershell 腳本會查看所有目前 IE URL,如果沒有 google 打開,則開啟 google.com,否則不執行任何操作。您需要將“*google”更改為“*yourbaseURLname”,將“www.google.com”更改為“www.yourwebsite.com”。 (腳本的最後 5 行)
將其儲存為 .ps1 檔案。
Function GetCurrentIEURL
{
$IEObjs = @()
$ShellWindows = (New-Object -ComObject Shell.Application).Windows()
Foreach($IE in $ShellWindows)
{
$FullName = $IE.FullName
If($FullName -ne $NULL)
{
$FileName = Split-Path -Path $FullName -Leaf
If($FileName.ToLower() -eq "iexplore.exe")
{
$Title = $IE.LocationName
$URL = $IE.LocationURL
$IEObj = New-Object -TypeName PSObject -Property @{Title = $Title; URL = $URL}
$IEObjs += $IEObj
}
}
}
$IEObjs
}
$CurrentIEURL = GetCurrentIEURL
if ($CurrentIEURL -NotContains "*google")
{
$IE=new-object -com internetexplorer.application
$IE.navigate2("www.google.com")
$IE.visible=$true
}