0

I need to launch two Google pages in full screen on a PC with 2 screens, one page for each screen.

Actually this is my code:

$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 

It works but it open one page over the other one. How can I do for open the second page on my second screen?

Albanese98
  • 13
  • 1
  • 6
  • You could use [this](https://stackoverflow.com/questions/41229932/is-it-possible-to-position-a-window-when-starting-a-process-with-powershell-sta) but specify the coordinates instead of getting them relative to the preselected screen. More ideas [here](https://stackoverflow.com/questions/10392620/how-can-a-batch-file-run-a-program-and-set-the-position-and-size-of-the-window/). – CherryDT Feb 03 '22 at 15:03
  • Already saw this but I think there is a way to do it in a simple way, I know that you can check how many screens you have connected with: [System.Windows.Forms.Screen]::allscreens.length . Maybe is possible launch the page on each screen with a for cycle – Albanese98 Feb 03 '22 at 15:37
  • The only ways (that I know about, at least) to set this _before_ the application is started would be 1) to pass the coordinates in the [`STARTUPINFO` structure](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfow) to [`CreateProcess`](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw) [...] – CherryDT Feb 03 '22 at 15:51
  • [...] or 2) to pass a `HMONITOR` handle in the [`SHELLEXECUTEINFO` structure](https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-shellexecuteinfow) to [`ShellExecuteEx`](https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecuteexw). - Both of these things are not exposed to PowerShell though and you need to go through more P/Invoke magic for them. – CherryDT Feb 03 '22 at 15:52

2 Answers2

0

This is application-specific in Windows, unfortunately. Windows processes (like explorer.exe) all use startup info stored in the registry, but that is not a standard and many applications ignore it entirely.

The only real global way around it is to emulate moving the window manually using some user32.dll methods like CherryDT's comment suggests.


To answer your example, Chromium browsers can use start flags to specify position, but it requires running each window with separate profiles:

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

I have found many other applications use a simple .ini file in appdata to store window size/location settings.

Cpt.Whale
  • 4,784
  • 1
  • 10
  • 16
0

im not sure if this is still needed for someone, but i marge two scripts to one and now its working fine :)

    $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 = 'www.domain1.com'enter code here
$startPage2 = 'www.domain2.com'

Start-Process -FilePath $pathToChrome ('--new-window',  '--start-fullscreen', '--user-data-dir=c:/screen1','--window-position=1680,0', $startPage1) -ErrorVariable Test 
Start-Process -FilePath $pathToChrome ('--new-window',  '--start-fullscreen', '--user-data-dir=c:/screen2','--window-position=0,0', $startPage2) -ErrorVariable Test