Link to home
Start Free TrialLog in
Avatar of DavidCox
DavidCox

asked on

Key Press or Post Message

How can I sendkeys or post a message to a 3rd party applications form or dialog box while the workstation is locked ??

Problem automated backup, run from an applications menu while the workstation is locked I can get the hwnd of the object and child objects but not sure how to interact with it!

Thanks Dave
Avatar of twalgrave
twalgrave

You can use the appactivate statement in VB, then issue Sendkeys.  If this doesn't work, use the keybd_event API.

Public Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)


If you need help with either of these, let me know.
You can use PostMessage to interact, or SendMessage.

I believe this is more or so what you are looking for, if you want to post messages.
Avatar of DavidCox

ASKER

Ok can anyone help me with the syntax.

I have the application Hwnd (AppHwnd) and the dialog box Hwnd (DialogHwnd) Class = #32770

In idiots Guide style:
How would I post User Name "Fred" ?? to the dialog box?

Thanks in advance

Dave
First of all, you must find a vessel to put Fred into.  That vessel could be the caption of the dialog box, a textbox or label on the dialog box, etc.  Where is Fred going?  If it's going somewhere that can accept a change in text, that's great, but you cannot expect to push the word "Fred" to another application and have it know what to do with it.

If I use Spy++ I can get a handle to the dialog box, but no reference to the TextBoxes (Input Fields) so I assume that the dialog is a lightweight control.

If the App is running without the workstation being locked I can wait to get the dialog hwnd then use
Sendkeys UserName, TRUE
Sendkeys "{TAB}" , TRUE
Sendkeys UserPwd, TRUE
Sendkeys "{ENTER}" , TRUE

This works and will log the user on.
But if the workstation is locked it will not work.

Dave
Ah we get to the crux.  You are filling in the textboxes with a value and then pressing the enter key.  I am assuming the problem is not in getting the handle to the dialog box while it is locked, but it is in activating the dialog box from within your code.

SendKeys requires the application to have the focus, but the keybd_evnt API doesn't.  Here's a great site with sample code and even a DLL that will help you with what you want.

http://www.froggy.com.au/andromeda/software/pushkeys/

I hope this helps!



ASKER CERTIFIED SOLUTION
Avatar of Guilt
Guilt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- split the points between twalgrave and Guilt
Please leave any comments here within the
next seven days.
Per recommendation, force-accepted.

Netminder
EE Admin

twalgrave: points for you at https://www.experts-exchange.com/questions/20434337/For-twalgrave-re-various.html