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.
-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
CodePudding user response:
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