Sign in to follow this  
Followers 0
karmayogi

Windows Services Stop Custom Action

3 posts in this topic

Guys,

I have been using this extremely useful utility put forth by arcker et al. as posted in http://www.autoitscript.com/forum/index.php?showtopic=80201 to build a windows service based application. One problem that I have is in writing my own custom stop function so that I can cleanup a bunch of files before the Service exits. I have problems with that when I write anything elaborate. I know it has something to do with timing because the SCM expects me to respond within a certain duration.

How do I plugin a custom method just like _Main() is currently plugged in, so that I can perform some stop actions ?

After that how do I control the timing part so that I get to perform some tasks without the SCM declaring failure.

Thanks

Yogi


I came, I saw and I copied.

Share this post


Link to post
Share on other sites



i think that in the service post someone as recoded the function, to use stop events fine.

think you get it there.

i have to publish his work too but i don't have so much time to remake a complete schema and a complete post.

will try to do so tomorrow, i guess


-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I have used the new script attached at the end of that service post submitted by another user. In that there is a stop action that is called by the control function calledback from the SCM, but my problem is when I add my custom code to perform some cleanup, it basically works only if I do simple tasks that finish quickly. If I add anything that takes a few seconds, then the service stop fails with error code 1053.

This is my sample from the function

Func _Service_Ctrl($ctrlCode)
    Switch ($ctrlCode)
        Case $SERVICE_CONTROL_PAUSE
            DllStructSetData($tService_Status, "dwCurrentState", $SERVICE_PAUSED)
        Case $SERVICE_CONTROL_CONTINUE
            DllStructSetData($tService_Status, "dwCurrentState", $SERVICE_RUNNING)
        Case $SERVICE_CONTROL_STOP
            _Service_ReportStatus($SERVICE_STOP_PENDING, $NO_ERROR, 60000)
    ; Here I call my custom cleanup function
            _PreStopEvent()
            _Service_ReportStatus($SERVICE_STOP_PENDING, $NO_ERROR, 0)
            _Service_SetStopEvent()
            _Service_Cleanup()
            Return
        Case $SERVICE_CONTROL_INTERROGATE
;break;
; invalid control code
;
        Case Else
;
    EndSwitch
    _Service_ReportStatus(DllStructGetData($tService_Status, "dwCurrentState"), $NO_ERROR, 0);
    
    
EndFunc;==>_Service_Ctrl

Any thoughts on why I get that error. I even provide a large waitHint, yet it does not seem to matter.

Thanks

Yogi

i think that in the service post someone as recoded the function, to use stop events fine.

think you get it there.

i have to publish his work too but i don't have so much time to remake a complete schema and a complete post.

will try to do so tomorrow, i guess

Edited by karmayogi

I came, I saw and I copied.

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