Jump to content

Application does not stop when set as a service


 Share

Recommended Posts

Hi folks

I created an application and I set it up as a service using the guidlines posted in the forums - there is a group of scripts called services.au3

Anyway the service is working fine it starts straightaway but when I go to stop it it does not stop I have to kill the process in order for it to stop.

Is there something I need in the application to allow it to say a stop request has been made please exit.

The script has a while loop in it that makes it loop every 2 minutes indefinitely - (the script is checking the status of the services on the box ironically)

So is due to the while loop perhaps or am I just way off the mark.

I am by no means a super programmer so go easy on me

Michael

Cheers

Link to comment
Share on other sites

Just off the top of my head, It might not be stop if depending on how the 2 minute event you mentioned is coded. Also, how are you running it as a service? With a 3rd party tool or using the Service code demonstrated

Link to comment
Share on other sites

It would be easier to help if you posted your code here.

:x

Just saying.

But @ your problem, the reason why this happens is because AutoIt scripts don't close by default until the loop is satisfied. In other words, you'll have to end the loop internally if you don't want this problem to occur externally.

spudw2k, the UDF you posted is probably too complex for someone fairly new to AutoIt. Besides, I don't think that's the solution to his problem. o.o

Edited by Kalin
Link to comment
Share on other sites

spudw2k, the UDF you posted is probably too complex for someone fairly new to AutoIt. Besides, I don't think that's the solution to his problem. o.o

I'd say the UDF would only make things too complex if you look at the backend code dealing with the SCM. :x It is a beast I admit, but there are very simple examples and it's definitely worth researching if the intention is to make an AutoIt Script that functions as a service.

It would be easier to help if you posted your code here.

Agreed

Edited by spudw2k
Link to comment
Share on other sites

HI spudw2k

Yes I am using the UDF as described and the service does install and starts and functions correctly but I don't obviously have a provision for stopping.

I have no problem posting code I have attached the file below.

I don't think the loop method is the most efficient however within the scope of my knowledge it is the best I could do so any help on improving this script would be really appreciated.

Cheers

MIchael

ServiceMonitoring.au3

Link to comment
Share on other sites

Just a couple of things.

When I used the Service UDF, it would call the func Main, but I don't see that in your code. Not sure if that's causing the problem or if you changed the UDF on your machine.

Anyways, here's what I recommend as far as the pause/sleep.

Instead of doing a sleep, have a timer running and if that timer reaches the desired duration, run the main code and reset the timer. The sleep command more-or-less hangs the process from what I understand.

Link to comment
Share on other sites

Hiya,

Do you have any examples of using a timer function, never thought of that I have used them before in VB.

I will check the Main() function I kind of figured this was just the way the example was coded.

When the stop command is sent from the Service control manager I wonder is there anything you need in your code to react to, I was thinking if I am sleeping for 2 minutes and then just looping I am not looking for something asking me to shutdown - now might not be needed but just a thought.

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