google-chrome - 通过Powershell启动过程在新标签页而不是新窗口中打开Chrome

标签 google-chrome powershell cmd

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

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

最佳答案

这将为我打开一个选项卡,而不是一个新窗口:

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

但是,如果您只想刷新页面(如您在注释中所说),则还可以在Powershell中使用一些WindowsScript,如下所示:
#  * 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')打开一个新标签页,但是由于某种原因,这会打开一个新窗口,然后再打开一个新标签页...

关于google-chrome - 通过Powershell启动过程在新标签页而不是新窗口中打开Chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43762170/

相关文章:

html - 防止 chrome 中的内联 SVG 像素捕捉

unit-testing - 如何使用 Pester 模拟对 exe 文件的调用?

windows - SVN:仅由作者或管理员更改日志消息

javascript - HTML5 视频 - 以编程方式显示/隐藏控件

google-chrome - 在 HKCU 中使用 ExtensionInstallForcelist 时,Chrome 扩展程序不会安装

powershell - 寻找纯 PowerShell IRC 客户端

json - 如何在 PowerShell 中查询 JSON 记录

go execute ssh command 并且无法在远程服务器上杀死命令

将文件解压缩到目录中的 Windows 批处理脚本