Jump to content

Clicking Controls in minimized/inactive Remote Desktop Session


Recommended Posts

I have recently written an AutoIT script (my first!) which opens an IE browser, navigates to a website, runs a report, and then clicks the necessary buttons to download a copy of the report as a .csv file. This script will be running on a Windows XP machine which will have a user logged in at all times, but the user's desktop may be locked or otherwise inactive. I have been connecting to the machine via Remote Desktop, and when I have the desktop displayed, the script runs just fine. It also runs just fine on my own machine.

When I run the script as a scheduled task when I am *not* connected to the remote desktop, or when I have the remote desktop minimized, the IE portions of the script appear to work properly, but the script hangs when the code I wrote to handle the IE popups (first a "File Download" popup where I am trying to push the "Save" button, then a "Save As" dialog where I am trying to set the file name and press the "Save" button). The relevant section of the code is below:

CODE
; Now set file type to ".csv" and Execute

$webwind = $open

$open = ""

$valid = 0

While($valid == 0)

While($open == "")

$open = WinGetHandle("File Download")

Sleep(500)

WEnd

$text = WinGetText($open, "")

$valid = StringRegExp($text, ".*salesforce\.com.*", 0)

If TimerDiff($starttime) >= 1800000 Then

Run(@ComSpec & " /c " & '"C:\Documents and Settings\exchmaint\My Documents\Scripts\failed-sfe-email.vbs"', "", @SW_HIDE)

Exit

EndIf

WEnd

Sleep( 1000 )

Dim $worked=0

While($worked == 0)

$worked=ControlFocus ($open, "", "Button2")

WEnd

$worked = ControlClick($open, "", "Button2")

$worked = ControlClick($open, "", "Button2")

; Now pick the file name. . . . .

$open = 0

$open = WinWait("Save As", "", 30)

$open = WinGetHandle("Save As")

ControlFocus("Save As", "", "Edit1")

Send("C:\temp\SalesForceContacts.csv")

Sleep(1000)

ControlClick("Save As", "", "Button2")

From debugging attempts, I believe the WinGetHandle and ControlFocus commands are working properly, and when I trapped the return value of the ControlClick command it came back as "1". Still, when I schedule this task and come back to the desktop later, I see the IE window up with the "File Download" dialog waiting for input. Any ideas?

Link to comment
Share on other sites

For what it's worth, I figured out a workaround and thought I would post it here. The "File Download" dialog in IE has apparently been coded so that no button presses are actually processed unless the window is active. My guess would be that this is intended behavior on the part of IE, to prevent malware from getting around file download confirmation by trapping the File Download dialog.

What I did was to alter the file type permissions for the file I was downloading (a .csv) in Windows Explorer to uncheck the "Confirm Open after Download" box (it's in Tools -> Folder Options -> File Type, click the "Advanced" button). This bypasses the dreaded IE "File Download" dialog and opens the downloaded file in a new window. I then trapped this window (in this case a Notepad Window) and I could manipulate *it* just fine in an inactive session.

Big thanks to the IE.au3 author, by the way. The IE sections of the code worked like a champ, even in an inactive Remote Desktop window, which I doubt was contemplated too much during its design.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...