ReeKorl

Issues running script as Windows service

6 posts in this topic

Good afternoon,

I'm having a couple of issues trying to get a script I have created to run as a Windows service. The basic scenario is that we have a number of production servers running Windows 2K8 R2 on all of which sit a third party application which communicates between two databases and periodically synchronizes them. When there is a temporary break in communications between the program and one of the databases, it throws two message boxes which must be clicked away before it attempts to repair communications. This functionality causes a lot calls to our support team, who have to remotely connect and click the OK button twice (only a 30 second job, but when it happens multiple times a day on each server it adds up to a large volume of support calls). Neither the bad infrastructure nor the fact that the message box must be clicked are in my power to change, so I went down the path of making a simple script with the following code:

Global $i = 0

Do
   Sleep (10000)
   InterfaceRestart()
Until $i = 1

Func InterfaceRestart()
   Local $hWnd1 = WinWait ("[TITLE:Interface; CLASS:#32770]","Data Base connection lost")
   WinActivate ($hWnd1)
   Sleep (500)
   ControlClick ($hWnd1, "", "[CLASS:Button; INSTANCE:1]", "primary", 1)
   Sleep (500)
   Local $hWnd2 = WinWait ("[TITLE:Database Info; CLASS:ThunderRT6FormDC]","")
   WinActivate ($hWnd2)
   Sleep (500)
   ControlClick ($hWnd2, "", "[CLASS:ThunderRT6CommandButton; INSTANCE:2]", "primary", 1)
EndFunc

The reason for the numerous Sleep() functions are to get around the fact that the servers are not particularly fast and without them the script just plain runs too fast for the OS and third party application to keep up. I also realize that this loop is probably not the best way of getting it to keep running, but I'll re-code that if I can get the proof of concept working (unless that's the problem obviously). The code is then compiled with Aut2Exe as I can't justify installing the full AutoIt interpreter on these servers to solve this one problem alone, however a standalone application is ok. When compiled this way and running as a regular application the script performs exactly as expected, waiting for the specified message box to pop up then sending a primary click to the OK button, then again for the second one. My reasoning for having it as a service is firstly to prevent accidental pausing of the script by one of my engineers right clicking on the icon in the systray and forgetting to un-pause it again once they're done, and secondly that we already have a remote monitoring system set up for numerous other services on these servers, to which adding another for this one is extremely simple.

The basic problem is that once this is created as a service it will not start, with return code of "The service is not responding to the control function. More help is available by typing NET HELPMSG 2186", which of course is no help whatsoever as the help just says the same thing as the initial error. The service is configured to run under the local system account, in its own memory space, delayed automatic start and with interactive mode on so it's able to send the commands to the desktop.

So... have I missed something fundamental in the script? Am I running into an issue with session 0 isolation in Windows? Is there some sort of path/file access permissions setup I'm missing? Is it just not possible to do this with a compiled standalone script? Is it something else entirely? Or am I just plain barking up the wrong tree trying this?

Thanks,

~~R

Share this post


Link to post
Share on other sites



I had just pointed the service entry to the script's compiled binary, although now you have said that I think that may be where I'm going wrong.

However, I initially skipped this part as I was under the impression that SrvAny wasn't supported post-Win2k3, or rather isn't Session 0 Isolation aware so would prevent me from using the script to interact with the desktop. If this isn't the case, would grabbing it from the 2k3 resource kit be sufficient to get it running on 2k8 R2? Admittedly I haven't looked too much into alternatives, mainly because most of what I could find from a quick search were commercial alternatives which I don't think I'll be able to get the bean-counters to sign off on.

~~R

Share this post


Link to post
Share on other sites

I am wondering why you want this as service and not simply run it with the scheduler?
The Service route will require a wrapper like SRVANY but I have no recent experience with that.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Mainly I wanted it as a service to allow our existing monitoring system to easily track and restart it if it went down, and to prevent the issue whereby if you right click on the systray icon it will pause the script, and doesn't restart it unless you specifically click on the ticked "Script Paused" option on the menu to un-pause it again - we don't have anything that can monitor whether the script is actually actively processing, just whether the process is loaded or not if going down the application route. If the script is paused, the process is still running, so our monitoring would be none the wiser that it's not actually doing anything.

As a stop-gap, I've now implemented it to trigger on login with the scheduler and it's working ok like that, it's just not quite as robust as I'd like the final solution to be. Sounds like I'm going to have to either make do with using it like that or look further into what service wrappers I can use in 2k8 though. Thanks for the input!

~~R

Share this post


Link to post
Share on other sites

@ReeKorl, to keep someone from right clicking and pausing the script, just use #NoTrayIcon, and set yourself a way to stop the script when you want with HotKeySet


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

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