本帖最后由 ivor 于 2019-10-15 18:04 编辑
- #requires -Version 2
- function Show-Process($Process, [Switch]$Maximize)
- {
- $sig = '
- [DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
- [DllImport("user32.dll")] public static extern int SetForegroundWindow(IntPtr hwnd);
- '
-
- if ($Maximize) { $Mode = 3 } else { $Mode = 4 }
- $type = Add-Type -MemberDefinition $sig -Name WindowAPI -PassThru
- $Process.Foreach{
- $hwnd = $_.MainWindowHandle
- $null = $type::ShowWindowAsync($hwnd, $Mode)
- $null = $type::SetForegroundWindow($hwnd)
- }
- }
- Show-Process (Get-Process -Name notepad)
复制代码 支持进程数组:前台化、最大化复制代码 |