Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Script that open an url then close the browser

I’m writing a PowerShell script that need to do the following task :

  • Open an url then close the windows that got open
Start-Process -FilePath msedge http://127.0.0.1:62354/now
Start-Sleep -Seconds 1
get-process msedge | %{ $_.closemainwindow() }

I’m facing 2 issues :

-First one : is I actually force to open the url with Edge so I could close it without any issue for knowing what default browser the user may use.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

-Second one : When I close the window it’s actually close all Edge process instead of the one that just got open which is troublesome since user may also use this browser to work on webapp

The first one would not be an issue if I could solve the second issue honestly

Hope you guys can help me

>Solution :

Think about it like this, when you open internet explorer, edge or chrome and browse to a URL, it sends an HTTP GET to the URL, which responds with an html file. It then does a GET for each script and file embedded on the page.

All you want to do is load this page for a second so you can register it on some server.

With that in mind, you don’t really need to browse to this webpage, you could just send a webrequest instead.

Try this instead!

Invoke-WebRequest http://127.0.0.1:62354/now
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading