user3797832
user3797832

Reputation: 7

RDP session launch applications

I have opened an RDP session using AutoIt. Here is the code:

$host = "" ; <---- IP 
$hGUI = GUICreate("Terminal Serveur", 952, 675, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$oRDP = ObjCreate("MsTscAx.MsTscAx.2")
$oRDP_Ctrl = GUICtrlCreateObj($oRDP, 64, 44, 800, 600)

GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetStyle($oRDP_Ctrl , $WS_VISIBLE)

$oRDP.DesktopWidth = 800
$oRDP.DesktopHeight = 600
$oRDP.Fullscreen = False
$oRDP.ColorDepth = 16
$oRDP.AdvancedSettings3.SmartSizing = True
$oRDP.Server = $host
$oRDP.UserName = "" ; <--- Username
$oRDP.Domain = ""
$oRDP.AdvancedSettings2.ClearTextPassword = "" ; <--- Password
$oRDP.ConnectingText = "Connecting to " & $host
$oRDP.DisconnectedText = "Disconnected from " & $host
$oRDP.StartConnected = True
$oRDP.Connect()
$oShel = ObjCreate("shell.application")
$oShel_Ctrl = GUICtrlCreateObj($oShel, 64, 44, 800, 600)
GUICtrlSetStyle($oShel_Ctrl , $WS_VISIBLE)
GUISetState(@SW_SHOW, $hGUI)

Send ("#r") ; !!

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            $oRDP.Disconnect()
            Exit
    EndSwitch
WEnd

Now, I want to launch an application in the RDP session. I tried " Send(#r) " in order to send the path with a function like SendKeys but this command is execute on my computer and not on the remote computer.

How can I do please?

Upvotes: 0

Views: 4321

Answers (2)

robertocm
robertocm

Reputation: 132

Update:

A much simpler alternative:

  • Change the Remote Desktop Connection Settings (not in the control code, but in the usual windows shorcut. But it seems that could be done in the AutoIt code with the keyboardhook setting keyboardhook setting ) .
  • Look for the Options button, in the window when launching remote desktop.
  • On the Local Resources Tab select Windows key combinations are applied in full-screen mode only.
  • Change this line in your code:

    $oRDP.Fullscreen = True

  • Include a pause to ensure the control has been loaded

    Sleep(5000)

    Send ("#r")

Previous answer:

Let my suggest a workaround not very 'elegant' but should work (tested ok):

In the remote desktop make a shorcut to the Windows Virtual Keyword (On-Screen Keyboard or OSK)

  • Find the position of the shorcut icon

  • In your code send a double click at this position to start the on-screen keyboard

  • Then send clicks to the positions of the desired keys

Something like this:

Sleep(5000)
MouseClick("left",512,191,2) ;start virtual keyword
Sleep(1000)
MouseClick("left",553,807,1) ;click
Sleep(100)
MouseClick("left",633,740,1)
Sleep(1000)
Send("notepad")
Sleep(1000)
Send("{ENTER}")

(Aside note: For any executable with a shortcut on the remote desktop simply send double click, without the need of the virtual keyboard)

Upvotes: 0

Glen
Glen

Reputation: 619

Send alt + home. This open the windows search in the rdp session, which you can then send it text e.g. send("notepad") send({enter})

Upvotes: 0

Related Questions