Maximize window and bring it in front with powershell


SUBMITTED BY: Guest

DATE: Nov. 14, 2013, 7 a.m.

FORMAT: Text only

SIZE: 959 Bytes

HITS: 868

  1. Maximize window and bring it in front with powershell
  2. [void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
  3. $shell = New-Object -ComObject “Shell.Application”
  4. $shell.MinimizeAll()
  5. $a = Get-Process | Where-Object {$_.Name -like "powershell"}
  6. [Microsoft.VisualBasic.Interaction]::AppActivate($a.ID)
  7. Set-ForegroundWindow (Get-Process PowerShell).MainWindowHandle
  8. Set-ForegroundWindow (Get-Process -id $pid).MainWindowHandle
  9. $sig = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
  10. Add-Type -MemberDefinition $sig -name NativeMethods -namespace Win32
  11. Stop-Process -Name Notepad -ea 0;Notepad.exe
  12. $hwnd = @(Get-Process Notepad)[0].MainWindowHandle
  13. # Minimize window
  14. [Win32.NativeMethods]::ShowWindowAsync($hwnd, 2)
  15. # Restore window
  16. [Win32.NativeMethods]::ShowWindowAsync($hwnd, 4)
  17. Stop-Process -Name Notepad

comments powered by Disqus