简体   繁体   English

如何在不同的显示器 (Windows) 中打开 Chrome 自助服务终端模式的两个实例

[英]How to open two instances of Chrome kiosk mode in different displays (Windows)

We are developing a web application that needs to open in two different browser instances each on a different Screen.我们正在开发一个 Web 应用程序,它需要在两个不同的浏览器实例中打开,每个实例都在不同的屏幕上。 Obviously the pc we are using has dual display already, and both monitors have the same size and resolution.显然,我们使用的 PC 已经具有双显示器,并且两台显示器具有相同的尺寸和分辨率。

The idea is that as soon as Windows starts the two applications should open immediately in fullscreen, our preferred browser is Chrome as it counts with several commands that might help us accomplish the task.这个想法是,一旦 Windows 启动,这两个应用程序应该立即全屏打开,我们首选的浏览器是 Chrome,因为它包含几个可能帮助我们完成任务的命令。

We have succeeded on adding to the startup programs two shortcuts that open two instances in kiosk mode, but we have not been able to choose on which Display to open.我们已经成功地向启动程序添加了两个快捷方式,可以在 kiosk 模式下打开两个实例,但我们无法选择要打开的显示。

The shortcuts have this target:快捷方式有这个目标:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir=c:\temp --kiosk www.domain.com --new-window "%1" --window-position=0,0

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir=c:\temp --kiosk www.domain2.com --new-window "%2" --window-position=1680,0

In order to open two instances chromes needs to create a temporary file with information of the instance to open (--user-data-dir=c:\\temp)为了打开两个实例,chromes 需要创建一个包含要打开的实例信息的临时文件(--user-data-dir=c:\\temp)

We tried using ( --window-position=1680,0 ) to specify where to open the instance but it seems that Chrome will give priority to the last position where the last instance was opened, so both instances open on the same window regardless of the command.我们尝试使用 ( --window-position=1680,0 ) 来指定打开实例的位置,但似乎 Chrome 会优先打开最后一个实例的最后一个位置,因此两个实例都在同一个窗口上打开,而不管命令。

We found this site with a list of all the commands available but the list is huge and we don't even know what we are looking for:我们找到了这个站点,其中列出了所有可用命令,但列表很大,我们甚至不知道我们在寻找什么:

http://peter.sh/experiments/chromium-command-line-switches/ http://peter.sh/experiments/chromium-command-line-switches/

I found this command: --display=:0.0 | --display=:0.1我找到了这个命令:--display --display=:0.0 | --display=:0.1 --display=:0.0 | --display=:0.1 But it doesn't seem to work or I am not using it properly --display=:0.0 | --display=:0.1但它似乎不起作用或我没有正确使用它

Any ideas?有任何想法吗? Thanks.谢谢。

This code worked fine for me:这段代码对我来说很好用:

start C:\Users\terminal\AppData\Local\Google\Chrome\Application\chrome.exe --app="http://www.domain1.com" --window-position=0,0 --kiosk --user-data-dir=c:/monitor1

start C:\Users\terminal\AppData\Local\Google\Chrome\Application\chrome.exe --app="http://www.domain2.com" --window-position=1680,0 --kiosk --user-data-dir=c:/monitor2

I think the order of the parameters is relevant.我认为参数的顺序是相关的。

I have the same issue also.我也有同样的问题。 This answer: https://stackoverflow.com/a/3750187/1305565 inspired me to create own PowerShell script for easier use.这个答案: https : //stackoverflow.com/a/3750187/1305565启发我创建自己的 PowerShell 脚本以便于使用。

Shortly不久

Script does the following:脚本执行以下操作:

  1. Start a Chrome instance via script通过脚本启动 Chrome 实例
  2. Now use WinApi to find started window and move it to the desired screen现在使用 WinApi 查找启动窗口并将其移动到所需的屏幕
  3. Send F11 key to the moved window to make it full screen (we could start chrome already in full screen mode, but moving windows in that mode would be not so trivial)将 F11 键发送到移动的窗口以使其全屏(我们可以在全屏模式下启动 chrome,但在该模式下移动窗口并不是那么简单)
  4. Do the same with other instances, specifying necessary URL.对其他实例执行相同操作,指定必要的 URL。

Final script最终剧本

Function definitions are hidden in Dll and in another helper script.函数定义隐藏在 Dll 和另一个帮助程序脚本中。 (download them from GitHub using the link above) (使用上面的链接从 GitHub 下载它们)

$chromePath = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
$chromeArguments = '--new-window --incognito'

# &taskkill /im chrome* /F 
Chrome-Kiosk 'http://google.com' -MonitorNum 1 
Chrome-Kiosk 'http://http://www.bbc.com/' -MonitorNum 2 

The easiest way to accomplish this is to use 2 different data directories.完成此操作的最简单方法是使用 2 个不同的数据目录。 You may or may not want to delete the preferences before launching.您可能想也可能不想在启动前删除首选项。 If you do, your script can control where screens are placed.如果这样做,您的脚本可以控制屏幕的放置位置。 If you don't, then they can be manually positioned and it will remember the position of both windows separately:如果不这样做,则可以手动定位它们,它会分别记住两个窗口的位置:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir=c:/screen1 --start-fullscreen --new-window www.domain.com --new-window "%1" --window-position=0,0

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir=c:/screen2 --start-fullscreen --new-window www.domain2.com --new-window "%2" --window-position=1680,0

Note, I also used --start-fullscreen instead of kiosk, and --new-window.请注意,我还使用了 --start-fullscreen 而不是 kiosk 和 --new-window。 You may or may not need those.您可能需要也可能不需要这些。

I'm having a very hard time finding an answer myself.我自己很难找到答案。

The closest-to-easy solution, since you're running Windows, that I could find was to create a batch file +VBScript that will emulate the Win+Arrow-keys shortcut to move a window to the 2nd display.由于您运行的是 Windows,我能找到的最简单的解决方案是创建一个批处理文件 +VBScript ,它将模拟 Win+箭头键快捷方式以将窗口移动到第二个显示器。 Here's a very well-written Tech-net Article (Shortcut is Win-7 specific I believe, but there are also graphics card manufacturer shortcuts)这是一篇写得很好的Tech-net文章(我相信快捷键是Win-7特定的,但也有显卡制造商的快捷键)

However, I did find a program that another forum claims you can create application shortcuts that launch in a specific window called DisplayFusion, check it out但是,我确实找到了一个程序,另一个论坛声称您可以创建在名为 DisplayFusion 的特定窗口中启动的应用程序快捷方式,请查看

You can also use the command-line utility mentioned here on Superuser <--- Probably the quickest method您还可以使用所提及的命令行实用程序在这里的超级用户“---也许是最快的方法

Hope this all helps,希望这一切都有帮助,

I run in the same problem and got setup a good solution with the command line flags.我遇到了同样的问题,并使用命令行标志设置了一个很好的解决方案。 The solution from https://stackoverflow.com/a/29646543/3634274 works also very well, but it needs some setup every time when i want to install new multimonitor stations and i have no named icons for each application. https://stackoverflow.com/a/29646543/3634274 中的解决方案也很有效,但每次我想安装新的多监视器站时都需要进行一些设置,并且每个应用程序都没有命名图标。

I use a combination of some command line flags and it works:我使用了一些命令行标志的组合,它可以工作:

Monitor 1:监视器 1:

--user-data-dir=C:\temp\App1
--app="http://appxy.appserver.my?station=PC-MYWORKSTATION&theme=dark"
--incognito
--window-position=0,0
--start-fullscreen

Monitor 2:监视器 2:

--user-data-dir=C:\temp\App2
--app="http://appxy.appserver.my?station=PC-MYWORKSTATION&theme=light"
--incognito
--window-position=2560,0
--start-fullscreen

It is important to use completly seperated user profiles, because when you have your Chrome with your profile open then it don't starts as it's own instance.使用完全分离的用户配置文件很重要,因为当您打开配置文件的 Chrome 时,它​​不会像它自己的实例那样启动。 With that setup i can use my chrome as it is and open my apps on the second or third monitor, eg like monitoring apps on which i only want to display stuff.通过该设置,我可以按原样使用我的 chrome 并在第二个或第三个显示器上打开我的应用程序,例如监控我只想显示内容的应用程序。

To make it easy for setup i wrote a powershell script that creates only the shortcut with a icon:为了便于设置,我编写了一个 powershell 脚本,该脚本仅创建带有图标的快捷方式:

# Example Call:
#
# Monitor 1
# .\createShortcut.ps2 -AppName "MyApp 1" -AppPath "http://google.com" -StartFullScreen $true -WindowPosition "0,0"
# .\createShortcut.ps2 -AppName "MyApp 1" -AppPath "http://google.com" -AppIcon "\\domain.local\icons\myapp.ico" -StartFullScreen $true -WindowPosition "0,0"
#
# Monitor 2
# .\createShortcut.ps2 -AppName "MyApp 2" -AppPath "http://google.com" -StartFullScreen $true -WindowPosition "2560,0"
# .\createShortcut.ps2 -AppName "MyApp 2" -AppPath "http://google.com" -AppIcon "\\domain.local\icons\myapp.ico" -StartFullScreen $true -WindowPosition "2560,0"

param(
  [string]$AppName,
  [string]$AppPath,
  [string]$AppIcon,
  [boolean]$StartFullscreen,
  [string]$WindowPosition
)

$AppArgs = " --incognito";

if($WindowPosition) {
  $AppArgs += " --window-position=$WindowPosition"
}

if($StartFullscreen -eq $true) {
  $AppArgs += " --start-fullscreen"
}

$userDir = "C:\temp\$AppName"
Write-Host "Create Folder:"$userDir
New-Item -ItemType directory -Path $userDir -Force > $null
$scArguments = "--user-data-dir=`"$userDir`" --app=`"$AppPath`"$AppArgs"

Write-Host "Argmunets: $scArguments"
$Shell = New-Object -ComObject WScript.Shell
$ShortCut = $Shell.CreateShortcut("$env:USERPROFILE\Desktop\$AppName.lnk")
$ShortCut.TargetPath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
$ShortCut.Arguments = $scArguments
$ShortCut.WorkingDirectory = "C:\Program Files (x86)\Google\Chrome\Application"
$ShortCut.WindowStyle = 1
if ($AppIcon.Length -gt 0) {
  $ShortCut.IconLocation = $AppIcon
}
$shortCut.Save()

I hope this solution helps all that searches for a similar solution.我希望这个解决方案可以帮助所有搜索类似解决方案的人。

Last but not least what does this script?最后但并非最不重要的是这个脚本是什么?

  • creates the user-data-dir silently静默创建用户数据目录
  • concats the command line parameters连接命令行参数
  • creates the shortcut with a icon (optional) on the desktop在桌面上创建带有图标(可选)的快捷方式

Here's how to do it with a Raspberry Pi/linux.以下是如何使用 Raspberry Pi/linux 进行操作。 These lines should be added to /home/pi/.config/lxsession/LXDE-pi/autostart这些行应该添加到 /home/pi/.config/lxsession/LXDE-pi/autostart

@chromium-browser --kiosk --incognito --user-data-dir=/home/pi/.config/chromium-display1 --window-position=0,0 https://bing.com 

@chromium-browser --kiosk --incognito --user-data-dir=/home/pi/.config/chromium-display2 --window-position=1921,0 https://google.com

If you need to find your screen resolution, go to Preferences > Screen Configuration.如果您需要找到您的屏幕分辨率,请转至首选项 > 屏幕配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM