【问题标题】:Powershell launch window on second screen第二个屏幕上的 Powershell 启动窗口
【发布时间】:2022-02-04 01:32:30
【问题描述】:

我需要在一台有 2 个屏幕的 PC 上全屏启动两个 Google 页面,每个屏幕一个页面。

其实这是我的代码:

$pathToChrome = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
$tempFolder = '--user-data-dir=c:\temp' # pick a temp folder for user data
$startmode = '--start-fullscreen' # '--kiosk' is another option
$startPage1 = 'https://google.com'
$startPage2 = 'https://google.com'

Start-Process -FilePath $pathToChrome ('--new-window',  '--start-fullscreen', $startPage1) -ErrorVariable Test
Start-Process -FilePath $pathToChrome ('--new-window',  '--start-fullscreen', $startPage2) -ErrorVariable Test 

它可以工作,但它打开一页而不是另一页。 如何在第二个屏幕上打开第二个页面?

【问题讨论】:

  • 您可以使用this,但指定坐标而不是获取相对于预选屏幕的坐标。更多想法here.
  • 已经看到了,但我认为有一种简单的方法可以做到这一点,我知道你可以检查你连接了多少个屏幕:[System.Windows.Forms.Screen]: :allscreens.length 。也许可以使用 for 循环在每个屏幕上启动页面
  • 在应用程序启动之前设置这个的唯一方法(至少我知道)是1)将STARTUPINFO structure中的坐标传递给@ 987654324@ [...]
  • [...] 或 2) 将 SHELLEXECUTEINFO structure 中的 HMONITOR 句柄传递给 ShellExecuteEx。 - 虽然这两个东西都没有暴露在 PowerShell 中,但您需要为它们使用更多的 P/Invoke 魔法。

标签: powershell window launch


【解决方案1】:

不幸的是,这在 Windows 中是特定于应用程序的。 Windows 进程(如 explorer.exe)都使用存储在注册表中的启动信息,但这不是标准,许多应用程序完全忽略它。

唯一真正的全局方法是使用一些 user32.dll 方法来模拟手动移动窗口,例如 CherryDT 的评论建议。


为了回答您的示例,Chromium 浏览器可以使用开始标志来指定位置,但它需要使用单独的配置文件运行每个窗口:

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

Launch Google Chrome from the command line with specific window coordinates

# open chrome on two monitors (all chrome windows must be closed first)
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --app="http://www.domain1.com" --window-position=0,0 --kiosk --user-data-dir=c:/monitor1

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --app="http://www.domain2.com" --window-position=1680,0 --kiosk --user-data-dir=c:/monitor2

我发现许多其他应用程序使用 appdata 中的简单 .ini 文件来存储窗口大小/位置设置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多