2

I have a C++ program that is launched using cmd. After being launched, he show off a pop up where the user has to write his login/password.

I want to launch this program with another program (wrote in C#), I know how to do that with System.Diagnostics.Process.Start.

So my question is: ho can I fill the login/password's fields in my C# program ?

Answer:

@DmitriyZapevalov was right. Here is some usefull links that helped me:

Thomas Perez
  • 129
  • 2
  • 13
  • http://stackoverflow.com/questions/15292175/c-sharp-using-sendkey-function-to-send-a-key-to-another-application – Sebastian Siemens Apr 28 '16 at 09:21
  • Thomas, can you share more details and source code if possible for how you achieve it? Also which type Visual C# project you used for it? – Kalpesh Jun 07 '16 at 09:27

1 Answers1

2

You have to use Windows API through Interop:

  1. Find popup's window handle (HWND)
  2. Find children fields handles
  3. Setup your text in fields by handles (SendMessage(WM_SETTEXT))

You can find fields and windows by names or IDs.

Use Spy++ to investigate popup window layout.

Dmitriy Zapevalov
  • 1,357
  • 8
  • 13
  • Do you have an example of use for this API ? – Thomas Perez Apr 28 '16 at 09:48
  • You can find each piece of this puzzle on StackOverflow. Search for PInvoke for [FindWindowEx](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633500(v=vs.85).aspx) for 1 and 2. And [WM_SETTEXT](https://msdn.microsoft.com/en-us/library/windows/desktop/ms632644(v=vs.85).aspx) for 3. – Dmitriy Zapevalov Apr 28 '16 at 09:56
  • So it's a C++ API. But I'm coding in C# so I don't know if it's solution to my problem. – Thomas Perez Apr 28 '16 at 11:57
  • Yes it is `C` Windows API but you can and should use it from `C#` using PInvoke. Just find C# help for each method here. Try to [search](http://stackoverflow.com/search?q=C%23+FindWindowEx) yourself and you will find [more](http://stackoverflow.com/questions/5673099/c-sharp-get-child-handles-using-findwindowex-by-name-and-ordinal-number) info. [Here](http://stackoverflow.com/questions/25718099/c-sharp-findwindowex-obtain-parameter-for-lpszclass-variable-by-winspy-not-wor) is qustion with `WinSpy++` from the same search query. – Dmitriy Zapevalov Apr 28 '16 at 12:11
  • Dmitriy, above solution worked and I was able to autofill it. Can you also add how can I `click the button` after autofill. – Kalpesh Jun 08 '16 at 12:38
  • Look there http://stackoverflow.com/questions/16295677/winapi-c-simulate-button-clicked-with-window-handle – Dmitriy Zapevalov Jun 08 '16 at 12:47