1

I wanted to: 1. In Windows, Determine the system's default browser 2. Pass the browser to a new-object definition 3. Open the browser and goto a url

This is what works so far:

    Function GET-DefaultBrowserPath {
        #Get the default Browser path
        New-PSDrive -Name HKCR -PSProvider registry -Root Hkey_Classes_Root | Out-Null
        $browserPath = ((Get-ItemProperty 'HKCR:\http\shel\open\command').'(default)').Split('"')[1]
        return $browserPath
    }

GET-DefaultBrowserPath

However, the only way I know how to open a browser and go to a url is:

$IE = new-object internetexplorer.application
$IE.navigate2("www.microsoft.com")
$IE.visible=$true

and this does not work:

$browser_object = new-object -com $browserPath.application

nor does this:

$browser_object = new-object -com firefox.application

Any help would be much appreciated.

Chris

2 Answers 2

4

The Start-Process cmdlet will open your default browser and navigate to the URL:

Start-Process $url
0
1

Try this:

$path = GET-DefaultBrowserPath
$url = "www.microsoft.com"
&$path $url

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.