Reputation: 974
I want to inject an address into the "Remote Desktop Connection" prompt using a VBScript. I was specifically told that I must employ Windows Automation API to do that, but after reading the documentation I didn't find any thing that could be used for VBScript. How can I proceed?
PS: As pointed out by Helen and this thread there is currently no support for VBScript to access UI Automation API.
Upvotes: 2
Views: 7994
Reputation: 97991
You don't actually need GUI automation here. To specify the computer to connect to, simply launch mstsc
with the /v
command-line argument, for example:
CreateObject("WScript.Shell").Run "mstsc /v:computername"
Alternatively, if you have an .rdp file containing the computer name and the connection settings, you can launch this file using mstsc
:
CreateObject("WScript.Shell").Run "mstsc E:\ComputerName.rdp"
If needed, you can generate an .rdp file on the fly, like this:
Dim oFSO, oShell, strFileName, strComputerName
strComputerName = "computername"
strFileName = "E:\ComputerName.rdp"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oStream = oFSO.CreateTextFile(strFileName, True)
oStream.WriteLine "full address:s:" + strComputerName
' TODO: Write other settings
oStream.Close
Set oShell = CreateObject("WScript.Shell")
oShell.Run "mstsc """ + strFileName + """"
Reply to comment:
however what I want to achieve is not the task of RDP-ing but the actual injection itself (this may be generalized into different windows of different applications).
Windows Script Host provides the AppActivate
and SendKeys
methods for GUI automation, but they aren't fool-proof.
I'd recommend using a GUI automation tool, for example, AutoIt (which is free). In AutoIt scripts, you can use the ControlSetText
function to change the text in input fields, for example:
Run("notepad.exe")
WinWait("[CLASS:Notepad]")
ControlSetText("[CLASS:Notepad]", "", "Edit1", "Hello, world!")
You can also use AutoIt's AU3Recorder to record user actions, so that you don't have to write scripts manually.
Upvotes: 9