How can I get the handle of each Firefox windows in Powershell? - powershell

I'm trying to get the handle of each windows opened by the firefox process. My use case is the following: on a computer in kiosk mode, I'm opening firefox at a specific URL with a powershell script at startup. That URL directs to an application that opens a new window that conveniently disable the use of the URL bar, preventing the user to browse the web. My problem is that the old window is still opened and I want to close it programmaticaly through that same powershell script. Although, the two windows have the exact same name so I can't use this to tell them apart.
I've tried listing the windows handles of the firefox process but it doesn't work since there is only one. I've also tried closing the main window of that process but since the pop up is coming up front, it's considered as the main window and so that is the windows that is closed.
There must be a way to select the correct window and close it because it is doable through the task manager.
edit: As a complement, I'd like to mention I tried what is mentioned in this thread but it doesn't work either.

I managed to circumvent my issue by launching firefox as a hidden window. The pop-up then comes up correctly and I'm happy with the result.
$firefox = Start-Process -FilePath "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -ArgumentList "https://myurl" -WindowStyle hidden
Start-Sleep -Seconds 2
Show-Process -Process $firefox

Related

Make ms-edge Window full screen (F11, normally) via powershell script

I'm trying to make ms-edge Window full screen (F11, normally) via powershell script.
This is an example of the powershell script I'm using to start edge:
Start-Process -FilePath msedge -ArgumentList '--new-window www.google.com'
This works fine. However, I want the edge window to be full-screen, like what happens when you press F11 while in the browser. This action cannot be dependent on the windows user or individual user ms-edge profile settings. I need it to be done from the script - if that is possible - so the action is the same for all users when they run the script.
Start-Process msedge.exe https:\\google.com -WindowStyle Maximized
if you're looking to start it in Full Screen mode, you can use the start-fullscreen switch.
--start-fullscreen.
So, it would be:
Start-Process -FilePath "msedge.exe" -ArgumentList '--new-window www.google.com --start-fullscreen'
Here are the content switches / source you can use, where start-fullscreen is shown as well.
I also recently wanted to open a web page in full-screen mode simply via a shortcut in autostart.
--start-fullscreen did not work, for whatever reason.
--kiosk www.google.com --edge-kiosk-type=fullscreen worked, but Edge is started in private mode and some functions no longer work.
Now I found out that --start-fullscreen does not work in connection with the "startup boost" of Edge. As soon as this is switched off in the settings, the parameter works again.

MS Edge: Powershell script to open three SEPARATE/independent MS Edge Windows (not tabs!)

I working on a network operations center type setup. On this particular PC, I have eight monitors. I have some software that will POSITION certain windows on certain monitors just after they launch. That's not my problem.
My problem is that each of the eight monitors needs to display a full screen instance of MS Edge. When I launch edge from a powershell script, each new launch of the application starts in a TAB of the FIRST instance of MS Edge instead of a completely independent window.
I'm using a powershell script like this as an example:
[system.Diagnostics.Process]::Start("msedge","https://something.com/somefile1.aspx")
[system.Diagnostics.Process]::Start("msedge","https://somethingelse.com/somefile2.aspx")
...however I'm open to using whatever powershell script syntax accomplishes my stated goal.
These open up in tabs instead of independent MS Edge application windows. Since this is in a NOC, I need to be able to script this independent of any windows user-specific settings - I need to be able to start the windows the same way regardless of which person is actually logging in.
Thanks in advance!
Use the --new-window switch
Start-Process -FilePath msedge -ArgumentList '--new-window www.google.com'
Start-Process -FilePath msedge -ArgumentList '--new-window www.bing.com'

How to open file in windows 10 default app from powershell

I am trying to write a simple shell script in powershell that opens a file in a default windows app and monitors the process to wait until the process has exited to continue. At a high level I would like to open a .mp4 file to trim it in the default windows 10 app. When manually editing the file it opens in the photos app to trim, I would like to automate the part of opening the file in the app.
Currently I'm able to monitor the photos app process and wait for the process to close using the following code:
Start-Process shell:AppsFolder\Microsoft.Windows.Photos_8wekyb3d8bbwe!App
Start-Sleep -Seconds 2
$proc = Get-Process -Name Microsoft.Photos
$proc.WaitForExit()
However I would like to start the process and pass in a filepath to open, for example:
Start-Process shell:AppsFolder\Microsoft.Windows.Photos_8wekyb3d8bbwe!App "C:\Some\Path\To\File.mp4"
If I can get the file to simply open in the photos app I can simply click the edit button manually but ideally I would be able to open the file in the edit UI like this:
Then the script would wait for the photos process to close to continue on. Does anyone have any ideas on how we can open a file in a default windows 10 app in this way from powershehll? Or if this is even possible?
Thank you!
I think you should explore the -Wait option of the Start-Process cmdlet
Start-Process "C:\Some\Path\To\File.mp4" -Wait

Open Multiple URLS with firefox in private mode using powershell

I am trying a script to make firefox open 1 private window with multiple URLs however the problem is if I have firefox open and run that script it opens 1 URL in private windows then opens another private window and opens the rest of the URLs
If I have Firefox closed and run that script it runs as expected and only 1 private window opens opening all URLs in different tabs
I tried that same script with google chrome and it works as expected wether I have chrome open or not so am assuming it is something related to firefox setting that I don't know about
$urls = #("https://google.com/","https://www.youtube.com/","https://www.facebook.com")
foreach($url in $urls){
start "C:\Program Files\Firefox Developer Edition\firefox.exe" -ArgumentList #( '-private-window' , $url)
}
I also tried the code in the following form:
start "C:\Program Files\Firefox Developer Edition\firefox.exe" -ArgumentList #( '-private-window' , 'https://google.com/')
start "C:\Program Files\Firefox Developer Edition\firefox.exe" -ArgumentList #( '-private-window' , 'https://facebook.com/')
start "C:\Program Files\Firefox Developer Edition\firefox.exe" -ArgumentList #( '-private-window' , 'https://youtube.com/')
Both codes do the same thing and I get the same results.
What I want is to open 1 private window regardless of how many tabs or windows I have open of firefox and open the URLs in the script in just this 1 private window.
Note: the above code works as expected in chrome so the issue is probably with firefox something needs to be changed am not sure what.
So I was finally able to reproduce your issue to some extent. If I run ur script 'as is' it would open 3 tabs in a private window. If I ran it again, it would add new tabs to that existing window.
Then I ran ur script with one normal window open and I think I saw your issue here. 2 private windows opened, one with 2 tabs and one with 1. The one with 2 tabs had one of the tab blank. so one of the URLs didnt open as expected.
On repetition, I figured it was not always the same URL that got "foxblocked" lol. So I added a delay in the foreach loop which seems to have done away with the issue I was seeing. Perhaps firefox.exe is not able to handle requests as fast as we were serving it.
$urls = #("https://google.com/","https://www.youtube.com/","https://www.facebook.com")
foreach($url in $urls){
start "C:\Program Files\Mozilla Firefox\firefox.exe" -ArgumentList #( '-private-window' , $url)
Start-Sleep -Seconds 1
}

PowerShell executes Notepad++ with other settings than from Start menu

When I start Notepad++ from Start menu, the window has certain dimensions and the font size is as I've set it to last time. However, then I execute it from PowerShell, the window is much smaller and so is the font size.
I suspect that I'm not executing the program with me as the invoker. Is that correct and what can I do about it?
I've tried both Invoke-Item and Start-Process but they both produced the same result (and I'm not sure about the difference between them, despite googlearching).
function Edit{
param([string]$file = " ")
Invoke-Item 'C:\Program Files (x86)\Notepad++\notepad++.exe ' $file
#Start-Process 'C:\Program Files (x86)\Notepad++\notepad++.exe' $file
}
If you are using above windows 7.
If you run Notepad++ as your account it will run as your standard account however if you launch it form an admin PowerShell session you will be launching Notepad++ in an admin session as well, which causes the Notepad++ to use a 'seperate profile' for lack of a better way of explaining it.
Basically your standard account and your admin account, although they may be your account, they aren't the same profile and are able to have different settings.