Paul777 Posted October 8, 2015 Share Posted October 8, 2015 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-okThis 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) @thenset SendKeys=CScript //nologo //E:JScript "%~F0"%SendKeys%@end// JScript sectionvar 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 Link to comment Share on other sites More sharing options...
MuffinMan Posted October 8, 2015 Share Posted October 8, 2015 ControlSend and ControlClick will be your new best friends.https://www.autoitscript.com/autoit3/docs/functions/ControlClick.htmhttps://www.autoitscript.com/autoit3/docs/functions/ControlSend.htm Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now