最大化窗口并使用powershell将其放在前面 [英] Maximize window and bring it in front with powershell

查看:96
本文介绍了最大化窗口并使用powershell将其放在前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从powershell在前面带一个窗口?我试着用这个来隐藏所有的窗口(工作)并把 powershell 带回来(不工作)

Is there a way to bring a window in front from powershell? I tried this to hide all windows (working) and bring me the powershell back (not working)

[void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
$shell = New-Object -ComObject "Shell.Application"
$shell.MinimizeAll()

$a = Get-Process | Where-Object {$_.Name -like "powershell"}
[Microsoft.VisualBasic.Interaction]::AppActivate($a.ID)

有什么建议吗?

推荐答案

PowerShell 社区扩展有一个 cmdlet 来帮助解决这个问题.你像这样使用它:

The PowerShell Community Extensions has a cmdlet to assist with this. You use it like so:

Set-ForegroundWindow (Get-Process PowerShell).MainWindowHandle

Set-ForegroundWindow (Get-Process -id $pid).MainWindowHandle

要激活/显示一个窗口,试试这个(假设你使用的是 PowerShell 2.0):

To activate/show a window try this (assuming you're on PowerShell 2.0):

$sig = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
Add-Type -MemberDefinition $sig -name NativeMethods -namespace Win32
Stop-Process -Name Notepad -ea 0;Notepad.exe
$hwnd = @(Get-Process Notepad)[0].MainWindowHandle
# Minimize window
[Win32.NativeMethods]::ShowWindowAsync($hwnd, 2)
# Restore window
[Win32.NativeMethods]::ShowWindowAsync($hwnd, 4)
Stop-Process -Name Notepad

这篇关于最大化窗口并使用powershell将其放在前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆