Canders_12
asked on
VBA SendKeys and Remote Desktop Connection
Hello all,
I have checked various places online with everyone saying sendkeys does not play nicely with Remote Desktop Connection. However, I just feel there must be some workaround out there. So my question is:
Is it possible to simply enter the following text "hello world" using VBA excel into a notepad file that is open within the remote desktop connection.
I dont mind having the remote desktop in a window and I don't mind alt and tabbing but at present whenever I try sendkeys it just closes the remote desktop connection. The code i was trying is as below:
Application.SendKeys ("%{TAB 3}"), True
Application.Wait Now + TimeValue("00:00:02")
Application.SendKeys ("Hello World"), True
Any help woule be greatly appreciated.
Many thanks.
I have checked various places online with everyone saying sendkeys does not play nicely with Remote Desktop Connection. However, I just feel there must be some workaround out there. So my question is:
Is it possible to simply enter the following text "hello world" using VBA excel into a notepad file that is open within the remote desktop connection.
I dont mind having the remote desktop in a window and I don't mind alt and tabbing but at present whenever I try sendkeys it just closes the remote desktop connection. The code i was trying is as below:
Application.SendKeys ("%{TAB 3}"), True
Application.Wait Now + TimeValue("00:00:02")
Application.SendKeys ("Hello World"), True
Any help woule be greatly appreciated.
Many thanks.
While you can create a compiled program to sendkeys to RDP, I think the link I posted (and from some other research) you can send keys via the API. I will attempt to do this for the both of us, but might take a while (re: other priorities). I'll ask to see if other E-E experts I know can help as well.
Dave
Dave
ASKER
dlmille:
I appreciate your comments. Any help you can give would be appreciated :)
I appreciate your comments. Any help you can give would be appreciated :)
ASKER
Oh dear, link didn't work :(
Try again. I did it just now from my blackberry
You can also go to the solutions tab above and search on sendkeys remote desktop to find it that way
Dave
You can also go to the solutions tab above and search on sendkeys remote desktop to find it that way
Dave
It might be till later tonite that I get to this. I thought to send the link so you'd have something to chew on:
http://207.46.16.248/en-us/library/aa381290(VS.85).aspx.
http://m8software.com/developer/keysend/sendkey.htm
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/01d1c501-880a-48c3-8b82-d3b08e974ff0/
Dave
http://207.46.16.248/en-us/library/aa381290(VS.85).aspx.
http://m8software.com/developer/keysend/sendkey.htm
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/01d1c501-880a-48c3-8b82-d3b08e974ff0/
Dave
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry, was a bit poorly yesterday so had a day out. Then just checked to see a flurry of activity :) will have a play and feedback :)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Unlike the "SendAKey" method I built with the example above, using this post: http://www.xtremevbtalk.com/showthread.php?t=293802, I could not get this: http://www.xtremevbtalk.com/archive/index.php/t-120500.html example to work with RDP, though I was able to emulate the keys sent via PostMessage to Microsoft Outlook.
Dave
Dave
The reason SendKeys etc. is bad is mainly because you have no way of specifying who gets the keypresses. If Google Talk or something steals focus, then it gets the keys. There are ways to turn off focus stealing, but also, SendKeys fails if the application is waiting for something else to finish and ignores your keys. You have to introduce wait intervals (which you must guess at the length of) before you send additional keys.
The SendMessage and PostMessage commands actually add commands to the message queues of the processes so it doesn't matter if it's busy or lost focus, it will still work. That is why those are better. I haven't used them much and never for Remote Desktop, but I thought I'd throw that out there to give direction.
The SendMessage and PostMessage commands actually add commands to the message queues of the processes so it doesn't matter if it's busy or lost focus, it will still work. That is why those are better. I haven't used them much and never for Remote Desktop, but I thought I'd throw that out there to give direction.
In my opinion, if you are just writing a short script for personal use, use whatever is quick and easy. But if this is part of a larger project or could ever be sent to a client, then do it the right way.
Of course, even in the first case, if you have time to learn a better way, then it will usually save headaches in the long run. I've started using good code practices even for short scripts because if I don't, invariably I'll come back to the script in a year or so to add a feature and will have trouble figuring out what I did.
Of course, even in the first case, if you have time to learn a better way, then it will usually save headaches in the long run. I've started using good code practices even for short scripts because if I don't, invariably I'll come back to the script in a year or so to add a feature and will have trouble figuring out what I did.
Let me recommend a tool to help with any of this.
http://www.softpedia.com/get/Security/Security-Related/Winspector.shtml
Winspector Spy (like Spy++ but supposedly better) tells you lots of information about all the open windows and processes on your system. You can use this to post and send messages to individual controls in a window (don't just send the keypresses to the "Remote Desktop Connection" window, send them straight to the edit control). It will also show you what messages you are sending when you click on things (almost like Excel's 'record macro' but for the Windows API).
If you want to do much Windows API stuff, this is a good tool to learn to use.
http://www.softpedia.com/get/Security/Security-Related/Winspector.shtml
Winspector Spy (like Spy++ but supposedly better) tells you lots of information about all the open windows and processes on your system. You can use this to post and send messages to individual controls in a window (don't just send the keypresses to the "Remote Desktop Connection" window, send them straight to the edit control). It will also show you what messages you are sending when you click on things (almost like Excel's 'record macro' but for the Windows API).
If you want to do much Windows API stuff, this is a good tool to learn to use.
ASKER
Crikey,
how do I distribute points?
Some great responses. Thank you everyone.
how do I distribute points?
Some great responses. Thank you everyone.
There's only two of us.
:) For what its worth, here's one more:
http://www.vbmonster.com/Uwe/Forum.aspx/vb-winapi/3551/SendMessage-vs-SendKeys
A link to a site where the guy built a class module around SendKeys. I tested it and it works. You can drop it in and use SendKeys and it does the work underneath the covers via keyboard API calls.
PS - I'm still trying to get SendMessage to work with Remote Desktop to no avail - can't seem to get a "handle" on the textbox as yet.
Dave
http://www.vbmonster.com/Uwe/Forum.aspx/vb-winapi/3551/SendMessage-vs-SendKeys
A link to a site where the guy built a class module around SendKeys. I tested it and it works. You can drop it in and use SendKeys and it does the work underneath the covers via keyboard API calls.
PS - I'm still trying to get SendMessage to work with Remote Desktop to no avail - can't seem to get a "handle" on the textbox as yet.
Dave
I'll take a look at Winspector. For login, anyway, Send and/or Post Message doesn't work via Edit control, for some reason.
Dave
Dave
ASKER
I know, people happy with 50.50 split?
Yep. Sounds fair.
ASKER
Greatly appreciated to you both.
I want help in sending commands like TAB, Enter, Down Arrow to remote login page. It's possible in local machine using SendKeys but I am unable to do this in a remote login page. After the remote login page appears, I can pass my username to the username field which is highlighted. I want to transfer the focus to password field by sending TAB or Down Arrow key command to the remote login page.
Can anybody help please? I am trying this since hours today.
Can anybody help please? I am trying this since hours today.
Here's a link which might work for both of us (I had put my problem on hold till I had the time to get the VB6 app going):
https://www.experts-exchange.com/questions/21208174/VB's-SendKeys-and-Remote-Desktop.html
Dave