Reputation: 574
I’ve put together some PS code that does the following inside of a larger PS script:
Make the IE process full screen
If (-Not (Get-Process IExplore -ErrorAction SilentlyContinue))
{
$navOpenInForegroundTab = 0x10000;
$ie = New-Object -Com InternetExplorer.Application
$ie.Visible = $True;
$ie.Navigate2("https://stackoverflow.com");
$ie.Navigate2("http://superuser.com", $navOpenInForegroundTab);
$sw = @'
[DllImport("user32.dll")]
public static extern int ShowWindow(int hwnd, int nCmdShow);
'@
$type = Add-Type -Name ShowWindow2 -MemberDefinition $sw -Language CSharpVersion3 -Namespace Utils -PassThru
$type::ShowWindow($ie.hwnd, 3) # 3 = maximize
}
Everything seems to work fine, except that after this code runs, it shows the number 24 in the PowerShell window (I am launching PS from the command line). Can anyone tell me why 24 is being displayed when I run the above code and is it possible to stop it from being displayed?
Upvotes: 1
Views: 3850
Reputation: 24535
This is the return value from the ShowWindow function. To ignore the result, use:
$type::ShowWindow($ie.hwnd, 3) | out-null
Upvotes: 1