关闭 WMI Explorer 的弹出窗口
来源:互联网 发布:采购业务数据字典 编辑:程序博客网 时间:2024/05/21 06:00
关闭 WMI Explorer 的弹出窗口
前两天下载了 WMI Explorer,想试用一下。
但是,直接就弹出一个激活的窗口。
说是可以从网站上申请试用激活码,但是要先注册;而注册的按键按下去没有任何反应。
Find-Window:负责找到弹出窗口的句柄。
正常窗口的句柄用 (Get-Process “$MainWindowsName`*”).MainWindowHandle 可以得到。
因为所有的操作都是以句柄为关键字。
Show-Window:负责显示、隐藏、最大化、最小化窗口。这个函数是微软 ShowWindowAsync 函数的示例。
Set-WindowStyle:负责改变窗口的样式。因为弹出窗口没有最小化按钮,通过 Find-Window -MainWindowsName "PowerShell Studio" | Set-WindowStyle -Style Style -newValue 0x14ef0000
,可以为弹出窗口加上最小化按钮。另外,被弹出窗口覆盖的主窗口是禁用的,即使弹出窗口已经隐藏,或者最小化,主窗口仍然不能操作,必须启用才行,比如:Set-WindowStyle -Name "PowerShell Studio"
$signature = @"[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);[DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd);[DllImport("user32.dll")] public static extern bool SwitchToThisWindow(IntPtr hWnd, bool fAltTab);[DllImport("user32.dll")] public static extern bool SetWindowLongPtr(IntPtr hWnd, Int32 nIndex, Int64 dwNewLong);[DllImport("user32.dll")]public static extern IntPtr FindWindow(String sClassName, String sAppName);[DllImport("user32.dll")]public static extern IntPtr FindWindowEx(IntPtr hwndParent,IntPtr hwndChildAfter,String sClassName, String sAppName);[DllImport("user32.dll")]public static extern IntPtr GetNextWindow(IntPtr hWnd, Int32 wCmd);[DllImport("user32.dll")]public static extern IntPtr GetWindow(IntPtr hWnd, Int32 wCmd);[DllImport("user32.dll")]public static extern Int32 GetWindowText(IntPtr hWnd, System.Text.StringBuilder lpString, Int32 nMaxCount);"@Function Find-Window{ Param( [parameter(Mandatory=$false, ValuefromPipeline = $false)] [string] $MainWindowsName, $PopupWindowsName, [parameter(Mandatory=$false, ValuefromPipeline = $false)] [String[]] [ValidateSet( "Child","EnabledPopup","First","Last","Next","Prev","Owner")] $Command = "Prev" ) switch ($Command) { "First" { $Cmd = 0 } "Last" { $Cmd = 1 } "Next" { $Cmd = 2 } "Prev" { $Cmd = 3 } "Owner" { $Cmd = 4 } "Child" { $Cmd = 5 } "EnabledPopup" { $Cmd = 6 } Default { $Cmd = 3} } if ( ! $PopupWindowsName ) { $PopupWindowsName = $MainWindowsName } $FindWindow = Add-Type -memberDefinition $signature -name "Win32GetWindow" -namespace Win32Functions -passThru $hMain = (Get-Process "$MainWindowsName`*").MainWindowHandle $hPrev = $FindWindow::GetWindow( $hMain, $Cmd ) $Title = New-Object -TypeName System.Text.StringBuilder $i = 0 do { $hPrev = $FindWindow::GetWindow( $hPrev, $Cmd ) $FindWindow::GetWindowText($hPrev, $Title, 1024) | Out-Null $i++ } until ($Title.ToString() -like "*$PopupWindowsName`*" -or $i -gt 100 )# $i $hPrev# $Title.ToString() } <# .SYNOPSIS Show, Hide Minimize, Maximize, or Restore the Powershell Console or other Window. .DESCRIPTION Show, Hide Minimize, Maximize, or Restore the Powershell Console or other Window. .PARAMETER WindowState [string] The New Window state Mode. May be one of the following: Hide Hides the window and activates another window. Normal Activates and displays a window. This is the Default. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time. ShowMinimized Activates the window and displays it as a minimized window. Maximize Maximizes the specified window. ShowNoActivate Displays a window in its most recent size and position. This value is similar to SW_SHOWNORMAL, except that the window is not activated. Show Activates the window and displays it in its current size and position. Minimize Minimizes the specified window and activates the next top-level window in the Z order. ShowMinNoActive Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated. ShowNA Displays the window in its current size and position. This value is similar to SW_SHOW, except that the window is not activated. Restore Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window. ShowDefault Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. ForceMinimize Minimizes a window, even if the thread that owns the window is not responding. This flag should only be used when minimizing windows from a different thread. .PARAMETER ID [Int32] The Process Identifier (PID) of the Target Window. If this paremeter is not specified the Target window defaults to the current Powershell Console Window. .INPUTS [Int32] $ID You can pipe Process Identifier (PID) of the Target Window. .OUTPUTS None Show-Window does not return any data. .Example PS C:\Users\User\Documents> Show-Window -WindowState Minimize Show-Window 853994 -WindowState Minimize This will Minimize the Powershell Console Window. #>function Show-Window{ param ( [Parameter(Mandatory = $false, ValueFromPipeline = $false)] [ValidateSet("Hide", "Normal", "ShowMinimized", "Maximize", "ShowNoActivate", "Show", "Minimize", "ShowMinNoActive", "ShowNA", "Restore", "ShowDefault", "ForceMinimize")] [String[]] $WindowState = "Normal", [Parameter(ParameterSetName = 'ID', Mandatory = $false, ValueFromPipeline = $true)] [Int32] $ID = $PID, [Parameter(ParameterSetName = 'Name')] [string] $Name ) Begin { $showWindowAsync = Add-Type -memberDefinition $signature -name "Win32ShowWindowAsync" -namespace Win32Functions -passThru switch ($WindowState) { "Hide" { $WinStateInt = 0 } "Normal" { $WinStateInt = 1 } "ShowMinimized" { $WinStateInt = 2 } "Maximize" { $WinStateInt = 3 } "ShowNoActivate" { $WinStateInt = 4 } "Show" { $WinStateInt = 5 } "Minimize" { $WinStateInt = 6 } "ShowMinNoActive" { $WinStateInt = 7 } "ShowNA" { $WinStateInt = 8 } "Restore" { $WinStateInt = 9 } "ShowDefault" { $WinStateInt = 10 } "ForceMinimize" { $WinStateInt = 11 } default { $WinStateInt = 1 } } } Process { if ($Name) { $showWindowAsync::ShowWindowAsync((Get-Process "*$Name*").MainWindowHandle, $WinStateInt) | Out-Null } else { #$showWindowAsync::ShowWindowAsync((Get-Process -id $ID).MainWindowHandle, $WinStateInt) | Out-Null $showWindowAsync::ShowWindowAsync( $ID, $WinStateInt) | Out-Null } }}<# .SYNOPSIS A brief description of the Set-WindowStyle function. .DESCRIPTION A detailed description of the Set-WindowStyle function. .PARAMETER ID A description of the ID parameter. .PARAMETER Style A description of the Style parameter. .PARAMETER newValue A description of the newValue parameter. .PARAMETER Name A description of the Name parameter. .NOTES Additional information about the function.#>function Set-WindowStyle{ [CmdletBinding(DefaultParameterSetName = 'ID')] param ( [Parameter(ParameterSetName = 'ID', Mandatory = $false, ValueFromPipeline = $true)] [Int32] $ID, [ValidateSet("ExStyle", "HInstance", "ID", "Style", "UserDate", "WndProc")] $Style = "Style", $newValue = 0x17cf0000, $Name ) begin { $SetWindowLongPtr = Add-Type -memberDefinition $signature -name "Win32SetWindowLongPtr" -namespace Win32Functions -passThru switch ($Style) { "ExStyle" { $StyleInt = -20 } "HInstance" { $StyleInt = -6 } "ID" { $StyleInt = -12 } "Style" { $StyleInt = -16 } "UserDate" { $StyleInt = -21 } "WndProc" { $StyleInt = -4 } default { $StyleInt = -16 } } } process { if ($Name) { $SetWindowLongPtr::SetWindowLongPtr((Get-Process "*$Name`*").MainWindowHandle, $StyleInt, $newValue) | Out-Null } else { $SetWindowLongPtr::SetWindowLongPtr($ID, $StyleInt, $newValue) | Out-Null } }}# wmi explorer 可以隐藏。Find-Window "wmi explorer" | Show-Window -WindowState NormalFind-Window "wmi explorer" | Show-Window -WindowState HideSet-WindowStyle -Name "wmi explorer"# PowerShell Studio,不能隐藏,一旦隐藏,就直接退出了,可恶。只能最小化。Find-Window -MainWindowsName "PowerShell Studio" | Set-WindowStyle -Style Style -newValue 0x14ef0000#Find-Window -MainWindowsName "PowerShell Studio" | Set-WindowStyle -Style ExStyle -newValue 0x00040310Find-Window -MainWindowsName "PowerShell Studio" | Show-Window -WindowState MinimizeSet-WindowStyle -Name "PowerShell Studio"
0 0
- 关闭 WMI Explorer 的弹出窗口
- excel privacy warning弹出窗口的关闭
- ymPrompt 自定义关闭弹出的子窗口
- 自动关闭webBrowser弹出的所有窗口
- 关于弹出消息窗口的自动关闭
- FastReport关闭弹出的进度条窗口
- 窗口弹出关闭汇总。
- 弹出关闭窗口汇总
- 弹出窗口自动关闭
- 关闭artdialog弹出窗口
- 关闭窗口的时候不弹出提示直接关闭
- 在父窗口关闭弹出的子窗口
- 点击窗口之外的区域将弹出窗口关闭
- Flex在窗口之外单击关闭弹出窗口的方法
- Winform关闭窗口时弹出确认窗口的实现
- 弹出showModalDialog窗口提交表单并关闭窗口的问题 (关闭又弹出新窗口问题)
- 访问使用自定义弹出对象的网页时,Internet Explorer 6 意外关闭
- flash安装时弹出:下列发生冲突的应用程序关闭后 安装将自动继续 internet explorer
- 关于onethink后台登录时(onethink前台有时也有)的验证码显示不出来的问题
- 拍照
- JAVA 上机作业4.1
- 值传递与引用传递
- TrueType字体的后缀名解释
- 关闭 WMI Explorer 的弹出窗口
- java记——关于continue的误区
- 第六周--数制转换
- POJ 2251 Dungeon Master(bfs)
- 正则表达式 “双向最小匹配”
- EntityFramework走马观花之 CRUD(上)
- Finding the factors of an integer
- ssoj2435 回文串游戏(贪心)
- Cygwin-安装和配置ssh服务