windows - 如何使用 Powershell 变量打开 Edge?

标签 windows powershell microsoft-edge

我尝试了以下方法:

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

但是我得到错误:

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

我在这里做错了什么吗?

编辑 17/07/2019 - 我已更改为以下内容:

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

现在 Edge 打开了,但是 Visible 和 Fullscreen 命令返回了错误 - 有人有什么想法吗?

干杯

最佳答案

我认为这可能是解决方案:

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

我在这里找到了上面的代码:start microsoft edge in fullscreen

您可以根据需要发送不同的键: How to send CTRL or ALT + any other key?

您可以找到要对 Edge 窗口执行的任何操作的快捷键。

你可以试试这个(来源是下面的链接):

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

还有一种在隐身模式下打开它的方法:

How to start Microsoft Edge in private mode by PowerShell

关于windows - 如何使用 Powershell 变量打开 Edge?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57053312/

相关文章:

linux - 如何将 git repo 从 Windows 克隆到 Linux?

c++ - NVidia NVML nvmlDeviceGetMemoryInfo() 立即加载和卸载 nvapi64.dll

windows - 为什么 xcopy 使用这些参数时不复制文件?

regex - PowerShell -replace 获取两个不同字符之间的字符串

google-chrome - Windows 10 上 chrome/edge 之间的时差

python - 如何删除小部件并在 python 中替换它们

powershell - 替换管道中的文字

powershell - 如何在powershell脚本中填写提示

css - Chrome 和 MS Edge 中 css 网格的不同结果

file-upload - 打开的文件似乎被锁定,无法在 Microsoft Edge 中上传