Oliver Aemmer
Oliver Aemmer

Reputation: 11

Powershell script presses F11 even if it's already in fullscreen

My script is almost done. It opens IE and switches between the tabs. Half of the time it works and it also goes into fullscreen mode. The problem is, if I execute it a second time, it is already set as fullscreen but it executes F11 so it stops fullscreen mode.

[void][System.Reflection.Assembly]::LoadWithPartialName( 
"Microsoft.VisualBasic")

add-type -AssemblyName System.Windows.Forms     
$ie = New-Object -ComObject "InternetExplorer.Application"  
$ie.Navigate("http://www.microsoft.com")
$ie.Navigate2("http://www.google.com" , 2048)
$ie.Navigate2("http://www.outlook.com" , 2048)
$ie.Navigate2("https://studer-ksg.intranet.koerber.de/de/nc/fritz-studer-ag.html" , 2048)
$ie.Visible = $true

start-sleep -Milliseconds 1000
$IEProcess = Get-Process | Where { $_.MainWindowHandle -eq $ie.HWND }
[Microsoft.VisualBasic.Interaction]::AppActivate($IEProcess.Id)

if($ie.fullscreen){

}else{
    start-sleep -Milliseconds 1000
    [System.Windows.Forms.SendKeys]::SendWait('{F11}')
}
do
{
    start-sleep -Milliseconds 4000
    [System.Windows.Forms.SendKeys]::SendWait('^{TAB}')
    start-sleep -Milliseconds 100
    [System.Windows.Forms.SendKeys]::SendWait("{F5}")
}
While ($i -ne 0)

How do I make an if to make it only press F11 if it isn't already in fullscreen when I start the script?

Thank you in advance

Upvotes: 0

Views: 2742

Answers (1)

Joey
Joey

Reputation: 354506

Is there a particular reason why you make things intentionally difficult here? Wouldn't this be much easier?

$ie.FullScreen = $true

Upvotes: 3

Related Questions