关闭 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
原创粉丝点击