I'd like to use "sendkeys" to an rdp session, but I think I'd first need to put the focus on the RDP window on my desktop. How can I determine that dynamically? If I use AppActivate, how can I determine the name of the RDP session?
Asked
Active
Viewed 506 times
0
-
4*I'd like to use "sendkeys"* - No, you don't. Not unless someone's forcing you at gunpoint. Trust me on that one. You're probably looking for [`AppActivate`](https://msdn.microsoft.com/en-us/library/wzcddbek%28v=vs.84%29.aspx), but again, you really don't want to use `SendKeys`. It's a very, *very* poor way of automating stuff, and should only be used as a last resort (if at all). – Ansgar Wiechers Jul 14 '15 at 22:34
1 Answers
0
AppActivate is the only window manipulation function available to script. As a general rule programs don't mess with other programs' windows.
However tasklist /v
lists the main window title for a program.
This code gets it from CMD.
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
Set cmd = CreateObject("Wscript.Shell").Exec("cmd")
cmd.stdin.writeline "tasklist /fi ""imagename eq mstsc.exe"" /v"
wscript.sleep 2000
cmd.stdin.writeline "exit"
Do While Not cmd.stdout.AtEndOfStream
results = cmd.stdout.readall
If err.number <> 0 then Exit Do
wscript.echo results
Loop
Also see my article here on how to access API from VBS using VB.NET. https://social.msdn.microsoft.com/Forums/en-US/df0248cb-612f-4e2f-9665-11c68c401458/this-is-how-to-call-win32-api-calls-in-vbscript-and-jscript-sample-windows-api-functions?forum=scripting
and How to find the window Title of Active(foreground) window using Window Script Host

Community
- 1
- 1

user5071892
- 147
- 2