开发者

How do I create an object based on the output of a Function in Power Shell?

开发者 https://www.devze.com 2023-04-11 06:10 出处:网络
I wanted to: 1. In Windows, Determine the system\'s default browser 2. Pass the browser to a new-object definition

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 wo开发者_Go百科rk:

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

nor does this:

$browser_object = new-object -com firefox.application

Any help would be much appreciated.

Chris


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

Start-Process $url


Try this:

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

精彩评论

暂无评论...
验证码 换一张
取 消