Jump to content
Sign in to follow this  

Run script on virtual server w/ no console or RDP session active

Recommended Posts



I'm trying to automate a process on one of servers. I have a basic script that does work however there are limitations. 

Script 1 - Working (application info removed, but you should get the general idea)

ShellExecute ($mpyApp & $fileName)
WinWaitActive("MyApp Title - " & $fileName)
AutoItSetOption("WinTitleMatchMode", 3)
WinWaitActive("MyApp Windows title 2")
AutoItSetOption("WinTitleMatchMode", 3)
WinClose("MyApp Windows title 2")
WinClose("MyApp Title - " & $fileName)

Currently to run this script I first have to launch an RDP session on the virtual server that this app is hosted on, log in as the admin, and run the script. The script performs perfectly after that. 

I want to take it a step further and run this script via a scheduled task each night. However here is the kicker - at night the RDP session wouldn't be active.

Ideally I do not want to create a process to launch RDP, then launch the script - instead, I just want the scheduled task to run with no additional steps. 

My understanding is that to do this I'd need to rewrite the script from scratch using ControlSend, WinActive, etc. etc. However, that doesn't seem to work near as easily.

Here is what I came up with

Script 2 - Not working


Func MyApp_Auto()

    ; Provide file name of the file you want automated
    $fileName = "UseThisOneKevin.yxmd"

    ; Run MyApp
    ShellExecute($MyApp & $fileName)
    Local $hWnd = WinWait($MyApp  & $fileName, "", 60)

    ; Wait for 2 seconds

    ; Send Control down + r + Control up to the windows
    ; This is part of the issue, the ControlID changes each time the app launches and so the controlID is an issue.
    ControlSend($hWnd, "", "Changes every time","{CTRLDOWN}r{CTRLUP}")

    AutoItSetOption("WinTitleMatchMode", 3)
    WinWait("MyApp Title Window 1")
    ; This window pops up when the process is completed.
    AutoItSetOption("WinTitleMatchMode", 3)
    WinClose("MyApp Title Window 1")
    WinClose($MyApp & $fileName)


I have left some notes in the script above outlining the problem areas but to sum up the script:

1) Launch Application by using a specified file

2) Ctrl+5 runs the application process to parse the file we opened in step 5

3) Once the workflow in step 2 finishes, a new window pops up to confirm the process finished

4) Close the Windows from Step 3

5) Close the Application


How can I accomplish this task in the way I've outlined? What am I missing?

I should note that my programming experience is fairly limited and I'm winging it to an extent so any feedback is welcome, however explanations will be necessary for me to understand.



Share this post

Link to post
Share on other sites

@KGThree you're not going to be able to execute remotely, with no session open, while relying on Sends. It sounds like (correct me if I am wrong) the script is on the remote server. Is it compiled or not? If so, I would suggest a couple of things:

  • Check out the AutoIt Window Info Tool (located in the same directory where you installed AutoIt) on the application you're trying to automate. If you are able to get the ID's for the various controls, you can use ControlSend instead of Send.
  • You can then look at PSExec to launch the script for you, under the administrative credentials.

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

How to get your question answered on this forum!

Share this post

Link to post
Share on other sites


You are correct in your understanding that the script is on the remote server. It is a compiled script.

The control ID's are different each time the application launches so using the Id number didn't work for me.

Share this post

Link to post
Share on other sites

I've never used PSExec, I'll have to look into that. 

Anyone else have any suggestions?

Share this post

Link to post
Share on other sites

There are other ways to identify the controls.   look in the helpfile for controlgethandle.  there is a link there that points to those different ways.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

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