Forum Discussion

thomas_brossama_1's avatar
9 years ago

Run a command prompt line disconnecting a RDP session without stopping test execution (as admin)

Hi,

 

I am struggling finding a way to disconnect automatically an RDP session so the remote test computer does not lock its session and makes failing the test execution (white screens due lock session).

 

I looked closely at the article - Disconnecting From Remote Desktop While Running Automated Tests

https://support.smartbear.com/viewarticle/72794/

 

Through a batch file, it is possible to disconnect so with the following batch file

for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
  %windir%\System32\tscon.exe %%s /dest:console
)

Manually in a command prompt, as admin, the command works fine.

 

However, When it comes to run it through TC11 I do not manage to use this batch file whether it is 

  • a Keyword (cannot get started the command line prompt as administrator, whereas I set the TestedApp to Run as and TestComplete is run as admin) or
  • or a vbscript. Here is my code

Sub SafeRDPDisconnection()

Dim WScriptObj, ExecOperation, ExCode, StdOut

Set WScriptObj = Sys.OleObject("WScript.Shell")

' disconnecting

Set ExecOperation = WScriptObj.Exec("cmd /c ""cd C:\my_project & disconnectRDPforTC.bat""")

' Get the operation's exit code

ExCode = ExecOperation.ExitCode

' Get the application's StdOut stream

Set StdOut = ExecOperation.StdOut

If ExCode = 0 Then

Call Log.Message("Connection succeeded", StdOut.ReadAll)

Else

Call Log.Error("Server is unavailable", StdOut.ReadAll)

End If

 

end Sub

 

It seems that the batch file is not run as admin.

 

Could you please shed some light? I believe that I am close to the solution.

 

In advance, thank you

Regards

Thomas

 

2 Replies

  • baxatob's avatar
    baxatob
    Community Hero

    I use this way as a workaround:

     

    1. Create a .bat file with above mentioned code - e.g. rdp_disconnect.bat

    2. Add rdp_disconnect.bat to TestedApps

     

    Now you can run your bat file when you need it -  TestedApps.rdc_disconnect.Run() 

     

    Also you can create a script with the same functionality.

    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      If you are able to use it, VNC is a good alternative to RDP as it doesn't mess with the user session and you can drop in and out of the remote machine as you please.