Focus IE window in powershell

2020-04-16 03:05发布

My code:

$ie = new-object -com "InternetExplorer.Application"
$ie.navigate("http://localhost")
$ie.visible = $true
$ie.fullscreen = $true

However, after fullscreen, the window still appears behind the Windows taskbar. When I click the window to give it focus, the taskbar falls behind and it appears how I want it to. How can I do this programmatically? Thank you!

1条回答
Emotional °昔
2楼-- · 2020-04-16 03:30

This was a toughy... Not as simple as I thought.

I ended up using a cheat and adding the VB assembly:

Add-Type -Assembly "Microsoft.VisualBasic"

$ie = new-object -com "InternetExplorer.Application"
$ie.navigate("http://localhost")
$ie.visible = $true
$ie.fullscreen = $true
While ($ie.Busy) { Sleep -m 10 }
$ieProc = Get-Process | ? { $_.MainWindowHandle -eq $ie.HWND }
[Microsoft.VisualBasic.Interaction]::AppActivate($ieProc.Id)
查看更多
登录 后发表回答