How to open Edge using Powershell variable?

淺唱寂寞╮ 提交于 2020-02-25 08:31:13

问题


I have tried the following:

$edge = New-Object -com microsoft-edge.application
$edge.visible = $true
$edge.FullScreen = $true

But I get error:

New-Object : Retrieving the COM class factory for component with CLSID 
{00000000-0000-0000-0000-000000000000} failed
due to the following error: 80040154 Class not registered (Exception from 
HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At line:1 char:9
+ $edge = New-Object -com microsoft-edge.application
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

Am I doing something obviously wrong here?

Edit 17/07/2019 - I have changed to below:

$edge = Start-Process -FilePath ($Env:WinDir + "\explorer.exe") 
-ArgumentList 
"shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge"
$edge.visible = $true
$edge.FullScreen = $true

So now Edge opens but the Visible and Fullscreen commands return errors - anyone have any ideas?

Cheers


回答1:


I think this might be the solution:

start microsoft-edge:http://google.com
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Google - Microsoft Edge')
Sleep 2
$wshell.SendKeys('{F11}')

I found the above code here:start microsoft edge in fullscreen

You can send edge different keys depending on what you want: How to send CTRL or ALT + any other key?

You could find the key shortcut to whatever you want to do to the Edge window.

You could try this(source is link below):

Start-Process -FilePath ($Env:WinDir + "\explorer.exe") -ArgumentList "shell:Appsfolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge"

There is also a way to open it in Incognito Mode:

How to start Microsoft Edge in private mode by PowerShell




回答2:


You could use the following command to open Microsoft Edge browser and navigate to the special URL.

start microsoft-edge:http://google.com

Edit:

If you want to use Edge Webdriver to open IE browser, you could download the Edge webdriver from this link, and refer to this article to use it.



来源:https://stackoverflow.com/questions/57053312/how-to-open-edge-using-powershell-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!