locked
Maximize a minimized window RRS feed

  • Question

  • I have a window minimized and need to bring it back to maximum. I find the window as below but not sure how it can be maximized. This object $a seems not doing the job. Any other idea? Thanks.

    $a = Get-Process | ? { $_.MainWindowTitle -eq 'Microsoft Excel - D:\test\Book1.xlsx' }

    PS C:\> $a.length

    1

    Wednesday, June 20, 2018 4:06 PM

Answers

    • Marked as answer by Ian3 Wednesday, June 20, 2018 9:11 PM
    Wednesday, June 20, 2018 4:12 PM
  • You can invoke a Maximize like this:

    $proc = Get-Process | ? { $_.MainWindowTitle -eq 'Planning.xlsx  -  Read-Only - Excel' }
    
    
    # Borrowed from https://blogs.technet.microsoft.com/heyscriptingguy/2015/12/26/weekend-scripter-manage-window-placement-by-using-pinvoke/
    Add-Type @"
        using System;
        using System.Runtime.InteropServices;
        public class myWindow {
            [DllImport("user32.dll")]
            [return: MarshalAs(UnmanagedType.Bool)]
            public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        }
    
    "@
    
    Function Maximize-Window() {
        Param(
            [System.Diagnostics.Process]$Process
        )
        $ShowMaximized = 3
        [void][myWindow]::ShowWindow($Process.MainWindowHandle, $ShowMaximized)
    }
    
    Maximize-Window -Process $proc

    • Marked as answer by Ian3 Wednesday, June 20, 2018 9:10 PM
    Wednesday, June 20, 2018 8:33 PM

All replies

    • Marked as answer by Ian3 Wednesday, June 20, 2018 9:11 PM
    Wednesday, June 20, 2018 4:12 PM
  • You can invoke a Maximize like this:

    $proc = Get-Process | ? { $_.MainWindowTitle -eq 'Planning.xlsx  -  Read-Only - Excel' }
    
    
    # Borrowed from https://blogs.technet.microsoft.com/heyscriptingguy/2015/12/26/weekend-scripter-manage-window-placement-by-using-pinvoke/
    Add-Type @"
        using System;
        using System.Runtime.InteropServices;
        public class myWindow {
            [DllImport("user32.dll")]
            [return: MarshalAs(UnmanagedType.Bool)]
            public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        }
    
    "@
    
    Function Maximize-Window() {
        Param(
            [System.Diagnostics.Process]$Process
        )
        $ShowMaximized = 3
        [void][myWindow]::ShowWindow($Process.MainWindowHandle, $ShowMaximized)
    }
    
    Maximize-Window -Process $proc

    • Marked as answer by Ian3 Wednesday, June 20, 2018 9:10 PM
    Wednesday, June 20, 2018 8:33 PM