Sign in to follow this  
Followers 0
Paul777

Windows scheduler and AutoIT

2 posts in this topic

Hello,

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"
%SendKeys%
@end

// JScript section

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

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

WshShell.SendKeys("% r");
WScript.Sleep(500);

WshShell.SendKeys("%r");
WScript.Sleep(1000);

WshShell.SendKeys("%n");

 

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")
Send("!r")

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.

Paul

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  
Followers 0