通过Powershell启动过程在新选项卡而不是新窗口中打开Chrome [英] Open chrome in new tab rather than new windows via powershell start-process

查看:430
本文介绍了通过Powershell启动过程在新选项卡而不是新窗口中打开Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

start-process "chrome.exe" '--profile-directory="Default"'

当我多次运行此命令时,它将在单独的窗口中打开我的默认配置文件镶边.当我的默认配置文件镶边已打开时,该怎么办才能打开新标签页?

When I run this command few times, it opens my default-profile chrome in separate windows. What can I do, to open new tabs, when my default-profile chrome is already opened?

推荐答案

这将为我打开一个标签页,而不是一个新窗口:

This will open a Tab instead of a new window for me:

start-process "chrome.exe" "http://localhost:9876/debug.html",'--profile-directory="Default"'

但是,如果您只想刷新页面(如您在评论中所说),那么您也可以在Powershell中使用一些WindowsScript,如下所示:

However, if you only want to refresh a page (like you said in the comments), you could also use a little WindowsScript inside of Powershell like this:

#  * Get a WindowsScript Shell
$WindowsScriptShell = New-Object -ComObject wscript.shell

#  * Check if Chrome is running and activate it
if ($WindowsScriptShell.AppActivate('Chrome')) {

    # * Take a nap to give Windows time to focus Chrome
    Sleep 2 

    # * Refresh the page by sending the F5 Key
    $WindowsScriptShell.SendKeys('{F5}')
}

# * If Chrome isn't there, tell us
Else {
    Write-Output "Chrome is not started!"
}

那接近吗?

使用VBScript,您还可以在刷新之前使用CTRL+<Number>组合键切换到特定选项卡.所以你必须添加 在F5键之前按$vbscriptShell.SendKeys('^2')键.我还尝试使用CTRL+T(在VBScript中为'^ T')打开新标签页,但是由于某些原因,这会打开一个新窗口,然后再打开一个新标签页...

With VBScript you could also use the CTRL+<Number> Combination to switch to a specific tab before refreshing. So you'd have to add $vbscriptShell.SendKeys('^2') before the F5 key. I also tried opening a new tab by using CTRL+T ('^T' in VBScript), but that opens a new window and then a new tab for some reason...

这篇关于通过Powershell启动过程在新选项卡而不是新窗口中打开Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆