Reputation: 1
I'm calling a .exe file using powershell script as below.
cmd.exe /c "C:\Users\Desktop\SomeExecutable.exe password:ABCD123"
When the password is correct, the executable runs smoothly.
When the password is wrong, there will be a popup message, saying the password is wrong.
When the popup message appears, powershell script waiting till user closes the pop message.
I want to programatically close this popup message.
Can you throw somelight how to achieve this?
Upvotes: 0
Views: 2303
Reputation: 7365
you can use windows API for this purpose as shown here:
http://www.codeproject.com/Articles/22257/Find-and-Close-the-Window-using-Win-API
You can also use powershell for that purpose:
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)
}
Upvotes: 3