Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, June 20, 2018 4:06 PM
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
All replies (2)
Wednesday, June 20, 2018 4:12 PM ✅Answered
https://community.spiceworks.com/topic/664020-maximize-an-open-window-with-powershell-win7
\(ツ)_/
Wednesday, June 20, 2018 8:33 PM ✅Answered
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