Jump to content
Sign in to follow this  

Windows scheduler and AutoIT

Recommended Posts


Using JScript and SendKeys I put together a simple piece of code that does the following:

1) Makes a particular window the active window.

2) Restores the window (in case it is minimised).

3) Presses the "Restart System" button using the alt+r keyboard shortcut.

4) Simulates pressing alt+n in case a warning box appears saying that the system is busy, i.e. actually working-ok

This worked perfectly.  However would not run overnight via Windows scheduler because of a limitation whereby you cannot use SendKeys when no-one is connected to the server or if the server is locked.

Here is the code:

@if (@CodeSection == @Batch) @then
set SendKeys=CScript //nologo //E:JScript "%~F0"

// JScript section

var WshShell = WScript.CreateObject("WScript.Shell");

WshShell.AppActivate("xi COMM - Workstation P3");

WshShell.SendKeys("% r");




Therefore I looked for an alternative that would be able to simulate pressing a button when no one is connected to the server.  AutoIT seemed like it would the perfect solution, and I presumed it would be using a more sophisticated approach than SendKeys.  For example by making use of API.  Therefore I put together the following two line piece of code to confirm that AutoIT would be able to run via Windows Scheduler on a server whilst I am not connected to the server:

WinActivate("xi COMM - Workstation P3")

This however appears to have exactly the same limitation as using SendKeys.  How can I get around this limitation?  Does AutoIT simply use SendKeys and therefore have the same limitation?  Surely it should use something more advanced such as API commands like SetAcitveWindow and BM_CLICK.  (I was unable to find any simple helpful examples that made use of SetActiveWindow and BM_CLICK, and this is why I turned to AutoIT.)

Any simple solution would be much appreciated, as I am really struggling to see a way around this problem.

Thanks for your help.


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  

  • Create New...