Jump to content
Sign in to follow this  
Ander

Issues with controlclick and remote desktop sessions

Recommended Posts

Ander

Hi there,

I'm developing a script to connect to multiple PC in our network stablishing RDP sessions. For security reasons in our organisation, there is a banner that is displayed after the user's credentials are put. All I need to do with AutoIT is to click the "OK" button of the "Remote Desktop Window" to fully start the session. I have used controlclick to do the job, the window is not selected and the session cannot fully start though. It is important to mention that the program should run in a locked PC, that's why I'm using controlclick. I've gone through several websites and haven't found much info about this issue, reason why I decided to post this question in this chat.

Do you guys think this is feasible with AutoIt or I should give it up and use a different programming language.

Thanks.

Share this post


Link to post
Share on other sites
Ander

This is the code I'm using:

$connectionName = "Cli123456-VM - Remote Desktop Connection"

while 1
   ConsoleWrite("Trying..." & @LF)
   ControlFocus($connectionName, "OK", "OPContainerClass1")
   Sleep(500)
   ControlClick($connectionName, "OK", "OPContainerClass1")
   Sleep(500)
   ConsoleWrite("Im waiting now..." & @LF)
   Sleep(10000)
   ConsoleWrite("Finished..." & @LF)
WEnd

Share this post


Link to post
Share on other sites
Earthshine

your while loop uses manual sleeps. this will never do for a reliable script. you need to loop while looking for the form that hosts that control. then poll the snot out of the controls until you find the one you want.

The problem is and always was, waiting. You have to actually wait until the control you want is visible and ready. Also, you can wait until the application is ready with WinWait or WinWaitActive sounds more like your needs. Then you can do a control focus and such.

WaitForControls.au3

Edited by Earthshine
clarify answers

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
JLogan3o13

Moved to the appropriate forum, as the DEV forum very clearly states

Quote

Do not create AutoIt-related topics here, use AutoIt General Help and Support

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Bert

I've seen this problem before - control click as far as I know can't interact with a remote desktop session. The only way around it I know of is you have to have a client server arrangement that will send commands to the RDS and inside that the client running on the RDS will send the controlclick. I hope that makes sense

  • Like 1

Share this post


Link to post
Share on other sites
Ander

Hi Earthshine,

Thanks for your reply, really appreciate it.

However, I got one more question as to your script:

According to the example given, I'm using the following parameters:

_checkClickCtrl('TscShellContainerClass', 'Cli123456-VM - Remote Desktop Connection', '[CLASS:OPContainerClass; INSTANCE:1]', '&OK', 0, 5000)

Am I doing something wrong?

If you want I can share the parameters I got with Au3Info tool.

Once again thanks for your support.

Share this post


Link to post
Share on other sites
Earthshine

Please share the information regarding the form that hosts the control you desire to click.

I know that RDP uses Dialog windows, so the $formclass should be something like [CLASS:#32770]

also from your code you are waiting forever for the control,  and then 5 seconds after the click. in most cases you will NEVER need to delay after clicking unless you want the user to see what is happening.

_checkClickCtrl('[CLASS:#32770]', 'Cli123456-VM - Remote Desktop Connection', '[CLASS:OPContainerClass; INSTANCE:1]', '&OK', 0, 0)

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

I would also like to ask you if your app that is connecting to RDP machines is built using Standard MS Controls? If it is .NET, then forget it.

I need to test everything we have, vb6 to WPF, so I went with TestStack.White and now develop all my automation using that Framework for the MS UI Automation, the MOAB of all windows testing.

AutoIt just can't do it, or do it as easily or well, plus... c# (or you can develop in ANY .NET language and develop to any version of .NET)

so if you are trying to automate WinForms or .NET stuff or WPF (newest windows apps use WPF), best of luck with AutoIt. It never worked for me and I am not going to try to blend two languages, I love C# and Python and can use either/both/any .NET language now. plus .NET languages are real OO, and I can use Reflection to save tons of test writing time.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Ander

I tried to use the parameters you sent to me, but I got the same result.

I'm basically using the default RDP client (mstsc.exe) and these are the details I got with Info tool:

>>>> Window <<<<
Title: QH11191959-VM - Remote Desktop Connection
Class: TscShellContainerClass
Position: 3840, 0
Size: 1920, 1080
Style: 0x160A0100
ExStyle: 0x00000000
Handle: 0x00180368

Its very disappointing, I just need to hit the "OK" button to start session, but my limitation is when we should lock the machine where we run the script.

If the machine isn't locked, I can use winactivate and send commands to do the job, and the script runs fine.

Do you think I should give up with this AutoIt?

Thanks.

Share this post


Link to post
Share on other sites
Ander

I tried to use the parameters you sent to me, but I got the same result.

I'm basically using the default RDP client (mstsc.exe) and these are the details I got with Info tool:

>>>> Window <<<<
Title: QH11191959-VM - Remote Desktop Connection
Class: TscShellContainerClass
Position: 3840, 0
Size: 1920, 1080
Style: 0x160A0100
ExStyle: 0x00000000
Handle: 0x00180368

Its very disappointing, I just need to hit the "OK" button to start session, but my limitation is when we should lock the machine where we run the script.

If the machine isn't locked, I can use winactivate and send commands to do the job, and the script runs fine.

Do you think I should give up with this AutoIt?

Thanks.

Share this post


Link to post
Share on other sites
Earthshine

Wow, when I use RDP and do a capture it looks like this for me:

 

Capture.jpg

Capture2.jpg


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

I would not give up just yet. the only reason I am pursuing TestStack.White is because I need to be able to test super old stuff to super new stuff for our company. If you are not a lover of code development, I do not suggest that route, but TestStack.White does all the waiting junk for you. you just describe what you want, control or whatnot, and what you want to do. it wraps the built in UI Autmation Framework from Microsoft.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

Hey, I did some testing and went through logging in, turns out, the response forms for RDP are XAML, so that is WPF baby. No AutoIT here will help you now.

 

 

WPFResponseForm.jpg

XAML_WPFResponseForm.jpg

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

Ok, more testing on Win7 2008R2, captured it looks like this is the connect button is [CLASS:Button; INSTANCE:5] with text 'Co&nnect'

Use these two. First one clicks the RDP forms Connect button. The next responds to the Windows Security OK button, which does not have a hotkey '&' character

 _checkClickCtrl('[CLASS:#32770]', 'Cli123456-VM - Remote Desktop Connection', '[CLASS:Button; INSTANCE:5]', 'Co&nnect')

_checkClickCtrl('[CLASS:DirectUIHWND; INSTANCE:1]', 'Windows Security', '[CLASS:Button; INSTANCE:2]', 'OK')

run that and get back at me.

In Windows 10, the Windows Security is a XAML based form (WPF like all new Windows Apps) so forget that AutoIt code if it works for you when you move to Win10

 

also, are you using AutoHotKey capture software??? Can't do that, need to use AutoIt's Frozen app.

TscShellContainerClass is AHK stuff. probably never work. the code I gave you should work if your parameter data is correct.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

just call %windir%\system32\mstsc.exe like this. make sure the windows text matches what you are passing it. If it just says Remote Desktop Connection then that is the text you pass my function, if it is that Cli12345 stuff, then you need that.

I have include an example that uses standard RDP mstcs.exe

Build and run test.au3, the logger I got off this site. it's all set to run the app, click the connect button and the OK button on Security. There may be other windows that pop up regarding security. I hope this helps.

log4a.au3

 

WaitForControls.au3

test.au3

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

I just extensively tested that on 2008R2 and Win10 latest build. works great, that that is in my local environment. yours will vary based on configuration.

on my machine, i can remark out the second line of test.au3 and it runs fine. it clicks the Yet button and away it goes. logger results below:

>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:D:\test.au3
+>11:29:23 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "D:\test.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
10\20\2017 11:29:23 | WARPCORE | Info | _checkClickCtrl():Begin
10\20\2017 11:29:23 | WARPCORE | Info | Searching for Formclass: [CLASS:#32770]
10\20\2017 11:29:24 | WARPCORE | Info | Searching for Text:Remote Desktop Connection
10\20\2017 11:29:24 | WARPCORE | Info | Searching for Control:[CLASS:Button; INSTANCE:5]
10\20\2017 11:29:24 | WARPCORE | Info | Searching for Ctrl Txt:Co&nnect
10\20\2017 11:29:24 | WARPCORE | Info | Timeout: 0
10\20\2017 11:29:24 | WARPCORE | Info | Time Delay (after click): 0
10\20\2017 11:29:24 | WARPCORE | Info | Control Text Search: Co&nnect
10\20\2017 11:29:24 | WARPCORE | Info | Control Text Found: Co&nnect
10\20\2017 11:29:24 | WARPCORE | Info | Found Formclass: [CLASS:#32770]
10\20\2017 11:29:24 | WARPCORE | Info | Found Text:Remote Desktop Connection
10\20\2017 11:29:24 | WARPCORE | Info | Found Control:[CLASS:Button; INSTANCE:5]
10\20\2017 11:29:24 | WARPCORE | Info | Found Ctrl Txt:Co&nnect
10\20\2017 11:29:24 | WARPCORE | Info | Timeout: 0
10\20\2017 11:29:24 | WARPCORE | Info | Time Delay (after click): 0
10\20\2017 11:29:24 | WARPCORE | Info | [CLASS:Button; INSTANCE:5]
10\20\2017 11:29:24 | WARPCORE | Info | ExitLoop:Normal - [CLASS:Button; INSTANCE:5]
10\20\2017 11:29:24 | WARPCORE | Info | _checkClickCtrl():End
10\20\2017 11:29:24 | WARPCORE | Info | _checkClickCtrl():Begin
10\20\2017 11:29:24 | WARPCORE | Info | Searching for Formclass: [CLASS:#32770]
10\20\2017 11:29:24 | WARPCORE | Info | Searching for Text:Remote Desktop Connection
10\20\2017 11:29:24 | WARPCORE | Info | Searching for Control:[CLASS:Button; INSTANCE:5]
10\20\2017 11:29:24 | WARPCORE | Info | Searching for Ctrl Txt:&Yes
10\20\2017 11:29:24 | WARPCORE | Info | Timeout: 5000
10\20\2017 11:29:24 | WARPCORE | Info | Time Delay (after click): 0
10\20\2017 11:29:24 | WARPCORE | Info | 2.27186695515771
10\20\2017 11:29:24 | WARPCORE | Info | Control Text Search: &Yes
10\20\2017 11:29:24 | WARPCORE | Info | Control Text Found: Co&nnect
10\20\2017 11:29:24 | WARPCORE | Info | 490.124373349127
10\20\2017 11:29:24 | WARPCORE | Info | Control Text Search: &Yes
10\20\2017 11:29:24 | WARPCORE | Info | Control Text Found: &Yes
10\20\2017 11:29:24 | WARPCORE | Info | Found Formclass: [CLASS:#32770]
10\20\2017 11:29:24 | WARPCORE | Info | Found Text:Remote Desktop Connection
10\20\2017 11:29:24 | WARPCORE | Info | Found Control:[CLASS:Button; INSTANCE:5]
10\20\2017 11:29:24 | WARPCORE | Info | Found Ctrl Txt:&Yes
10\20\2017 11:29:24 | WARPCORE | Info | Timeout: 5000
10\20\2017 11:29:24 | WARPCORE | Info | Time Delay (after click): 0
10\20\2017 11:29:24 | WARPCORE | Info | [CLASS:Button; INSTANCE:5]
10\20\2017 11:29:24 | WARPCORE | Info | ExitLoop:Normal - [CLASS:Button; INSTANCE:5]
10\20\2017 11:29:24 | WARPCORE | Info | _checkClickCtrl():End
+>11:29:24 AutoIt3.exe ended.rc:0
+>11:29:24 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.807

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

Got it working, but DirectUI forms are tricky, timing wise ( notice I needed to add a delay after the Connect button click!! That is because that response form is code and XML and you need to wait extra long!!) This is verified on Windows 7 and Server 2008R2. Windows 10 I have yet to make work, but it might be possible. Never give up.

this worked for me to get the button. notice I got it working with standard AutoIt function first

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include 'WaitForControls.au3'
#include 'log4a.au3'

#Region ;**** Logging ****
; Enable logging and don't write to stderr
_log4a_SetEnable()
; Write to stderr, set min level to warn, customize message format
_log4a_SetErrorStream()
_log4a_SetMinLevel($LOG4A_LEVEL_INFO)
; If @compiled Then _log4a_SetMinLevel($LOG4A_LEVEL_WARN) ; Change the min level if the script is compiled
_log4a_SetFormat("${date} | ${host} | ${level} | ${message}")
#EndRegion ;**** Logging ****

Run('c:\windows\system32\mstsc.exe')
$handle = WinGetHandle('mstsc.exe')

_checkClickCtrl('[CLASS:#32770]', 'Remote Desktop Connection', '[CLASS:Button; INSTANCE:5]', 'Co&nnect', 0, 500)
;~ ControlClick('Windows Security', '', '[CLASS:Button; INSTANCE:2]')
_checkClickCtrl('Windows Security', 'Windows Security', '[CLASS:Button; INSTANCE:2]', 'OK', 5000)
_checkClickCtrl('[CLASS:#32770]', 'Remote Desktop Connection', '[CLASS:Button; INSTANCE:5]', '&Yes')
 

test.au3

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Earthshine

Using the UIAutomation stuff developed by these guys here you can control .net, but to me, it was easier just to move to C# and use TestStack.White

https://github.com/jvanegmond/au3_uiautomation

This stuff for AutoIT does not work in Windows 10, latest builds so... I vote to go for using Microsoft's Visual Studio and Coded UI apps in C# or use TestStack.White with Visual Studio

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Ander

Hey Earthshine, thanks for keeping up with this query and sorry I did not get back to you before but I was away from my desk for a couple of days.

Now let me give you more details about the RDP connection I'm establishing against PCs on the network:

- I can login without problems to the machines. My real issue is after passing credentials, I get the following screen:Capture.GIF

As you can observe, the conditions of use come up after I logged in, still all I need to do is to hit that OK button to complete the process because I have another script in the startup folder which would run.

- These are the details I got with Window info tool:

Capture1.GIF

- Also I'm running this AutoIT script from both OSs Win 7 and Win 10.

I'll keep trying and if I get something important Ill keep you posted.

Thanks for your help.

Share this post


Link to post
Share on other sites
Earthshine

can you just use the Send command at that point?

Send('{Enter}')

that may work.


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.