使用powershell脚本关闭对话框

使用powershell脚本关闭对话框,powershell,Powershell,我正在使用powershell脚本调用一个.exe文件,如下所示 cmd.exe /c "C:\Users\Desktop\SomeExecutable.exe password:ABCD123" 密码正确后,可执行文件将平稳运行。 当密码错误时,将弹出一条消息,说明密码错误 当弹出消息出现时,powershell脚本将等待用户关闭弹出消息。 我想通过编程关闭此弹出消息 您能告诉我们如何实现这一点吗?您可以使用windows API实现此目的,如下所示: 您也可以为此目的使用powers

我正在使用powershell脚本调用一个.exe文件,如下所示

cmd.exe /c "C:\Users\Desktop\SomeExecutable.exe password:ABCD123"
密码正确后,可执行文件将平稳运行。 当密码错误时,将弹出一条消息,说明密码错误

当弹出消息出现时,powershell脚本将等待用户关闭弹出消息。

我想通过编程关闭此弹出消息


您能告诉我们如何实现这一点吗?

您可以使用windows API实现此目的,如下所示:

您也可以为此目的使用powershell:

Add-Type -Name ConsoleUtils -Namespace WPIA -MemberDefinition @'
[DllImport("user32.dll")]
    public static extern int FindWindow(string lpClassName,string lpWindowName);
    [DllImport("user32.dll")]
    public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);

    public const int WM_SYSCOMMAND = 0x0112;
    public const int SC_CLOSE = 0xF060;

'@
#find console window with tile "QlikReload" and close it. 

[int]$handle = [WPIA.ConsoleUtils]::FindWindow('ConsoleWindowClass','QlikReload')
if ($handle -gt 0)
{
   [void][WPIA.ConsoleUtils]::SendMessage($handle, [WPIA.ConsoleUtils]::WM_SYSCOMMAND, [WPIA.ConsoleUtils]::SC_CLOSE, 0)
}  

为此,您可以使用windows API,如下所示:

您也可以为此目的使用powershell:

Add-Type -Name ConsoleUtils -Namespace WPIA -MemberDefinition @'
[DllImport("user32.dll")]
    public static extern int FindWindow(string lpClassName,string lpWindowName);
    [DllImport("user32.dll")]
    public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);

    public const int WM_SYSCOMMAND = 0x0112;
    public const int SC_CLOSE = 0xF060;

'@
#find console window with tile "QlikReload" and close it. 

[int]$handle = [WPIA.ConsoleUtils]::FindWindow('ConsoleWindowClass','QlikReload')
if ($handle -gt 0)
{
   [void][WPIA.ConsoleUtils]::SendMessage($handle, [WPIA.ConsoleUtils]::WM_SYSCOMMAND, [WPIA.ConsoleUtils]::SC_CLOSE, 0)
}  

为什么要使用
cmd.exe
运行可执行文件?您不需要这样做。您可以使用powershell(只需谷歌搜索powershell SendKeys)来完成此操作,但在我的建议中,如果您可以判断出有错误,您最好停止进程。如果您确实需要先检查窗口并使用sendkeys,我建议您使用更适合该窗口的工具,例如AutoIt。为什么要使用
cmd.exe
来运行可执行文件?您不需要这样做。您可以使用powershell(只需谷歌搜索powershell SendKeys)来完成此操作,但在我的建议中,如果您可以判断出有错误,您最好停止进程。如果您确实需要先检查窗口并使用sendkeys,我建议您使用更适合该窗口的工具,例如AutoIt。