1

I’ve put together some PS code that does the following inside of a larger PS script:

  • Test if an IE process is already running
  • If IE is not already running, start a new process, open site one in that process then open site two in the foreground tab of that process
  • 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?

4
  • This might be return value from the ShowWindow function. If this is the case you would write $type::ShowWindow($ie.hwnd, 3) | out-null. Commented Dec 30, 2014 at 13:37
  • Yes, it's from ShowWindow. If it's a non-zero value, then the window was not previously hidden, i.e. it's visible, that's what it means. More about it here: msdn.microsoft.com/en-us/library/windows/desktop/… Commented Dec 30, 2014 at 13:39
  • Excellent - thank you. That is what was going on and the script now runs B-E-A-UTIFULLY Commented Dec 30, 2014 at 13:48
  • @STGdb post it as an answer and accept Commented Dec 30, 2014 at 16:56

1 Answer 1

1

This is the return value from the ShowWindow function. To ignore the result, use:

$type::ShowWindow($ie.hwnd, 3) | out-null
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.