Jump to content

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


KGThree
 Share

Recommended Posts

Hello,

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)
Send("{CTRLDOWN}r{CTRLUP}")
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

MyApp_Auto()

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
    Sleep(2000)

    ; 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")
    Sleep(30)
    WinClose($MyApp & $fileName)
    

EndFunc

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.

 

Thanks!

Link to comment
Share on other sites

  • Moderators

@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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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