beigeworm

HideWindow

Dec 20th, 2023
1,599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $Async = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
  2. $Type = Add-Type -MemberDefinition $Async -name Win32ShowWindowAsync -namespace Win32Functions -PassThru
  3. $hwnd = (Get-Process -PID $pid).MainWindowHandle
  4. if($hwnd -ne [System.IntPtr]::Zero){
  5.     $Type::ShowWindowAsync($hwnd, 0)
  6. }
  7. else{
  8.     $Host.UI.RawUI.WindowTitle = 'hideme'
  9.     $Proc = (Get-Process | Where-Object { $_.MainWindowTitle -eq 'hideme' })
  10.     $hwnd = $Proc.MainWindowHandle
  11.     $Type::ShowWindowAsync($hwnd, 0)
  12. }
Advertisement
Add Comment
Please, Sign In to add comment