0

I'm calling a .exe file using powershell script as below.

cmd.exe /c "C:\Users\Desktop\SomeExecutable.exe password:ABCD123"

enter image description here 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. enter image description here

I want to programatically close this popup message.

Can you throw somelight how to achieve this?

Squashman
  • 13,649
  • 5
  • 27
  • 36
  • 1
    Why are you using `cmd.exe` to run the executable? You should not need to. – Squashman Jul 03 '18 at 14:57
  • You can do this with powershell (just google for Powershell SendKeys) but in my opnion you would be better off just killing the process if you can tell that there was an error. If you really need to check for the window first and use sendkeys I would recommend using a tool that is more tailored to that such as AutoIt. – EBGreen Jul 03 '18 at 14:59
  • https://www.raymond.cc/blog/disable-program-has-stopped-working-error-dialog-in-windows-server-2008/ – Ctznkane525 Jul 03 '18 at 15:02

1 Answers1

3

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)
}  
S.Spieker
  • 7,005
  • 8
  • 44
  • 50