CB_SELECTSTRING ignored on some machines

2019-09-05 18:57发布

问题:

I am using user32 library to automate some out of browser clicks on Windows, IE - "save as" dialog in particular. My solution works fine on my box however on other computers not really.

The problem is when I am setting download path in a combobox, the file name I am passing in is just ignored and the original value is used. Other messages are accepted just fine on both environment, this includes clicking buttons, getting handles to windows, iterating windows, you name it.

I know it is quite broad question, but any idea what could influence such behaviour ? I believe my code is correct, so I am searching the cause elsewhere, like permissions, different user32 versions, ... ??

Following will display the text in the combobox, select string will succeed, but once the save button is clicked, original value is used.

 User32.SendMessage(combobox, User32Constants.CB_ADDSTRING, 0, DownloadAsFileName);
 var selected = User32.SendMessage(pointerToParent, User32Constants.CB_SELECTSTRING, -1, DownloadAsFileName);

I tried different techniques of getting the destination path into the combobox, however same results. Works on my box only, I can see then sendmessages are returning expected results, but the default value is used instead.

User32.SendMessage(editPartOfCB, User32Constants.WM_SETTEXT, DownloadAsFileName.Length, DownloadAsFileName);
User32.SendMessage(combobox, User32Constants.CB_SETCURSEL, 0, IntPtr.Zero);

Any help appreciated !

回答1:

Depending on the method you use for changing the file name, send an appropriate WM_COMMAND notification to the parent of the ComboBox (CBN_SELCHANGE or CBN_EDITCHANGE)



回答2:

Wild guess: The application that you are targeting is a higher privilege application and Windows is blocking your messages.

Try running your process as Administrator and see if that effects the results.