>>Seems you can set SCM service shutdown order using HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\PreshutdownOrder.
>
>That is what I am looking at. Thanks for mentioning it as well.
>
>>Also, there is the SetProcessShutdownParameters func :
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686227(v=vs.85).aspx - but I'm not sure it would help.
>
>I will take a look at that. Thanks for the reference
>
>>But I don't think any of the above will get round the time limit when there is a system shutdown - only the registry WaitToKillServiceTimeout affects that - and, AFAICS, that value is the time to allowed to shut down *all* services.
>>
>>Don't know what would happen if you set a high priority task to run on shutdown and made that responsible for shutting down the services. Might be an alternative?
>>
>>But, as before, the safest approach is to make service processes more atomic (i.e. interruptable). Can you give an example of a service job where that cannot be done ?
>
>But, a 7-minute loop to execute is something that has to complete, if it is in progress, so the entire scenario is to block all closure of other services until ours are finished.
>
>Also, the RequestAdditionalTime(30000) seems to have a maximum value. I cannot put a value to high in there. I haven't done much tests yet. But, so far, it seems, it the value is over that that it would not work. Also, when this is effective, I see that it gets into the OnShutDown a second time, after 30 seconds, but then, it will ignore a second request and will simply proceed with the OnShutDown.
I did a quick test on OnStop:
RequestAdditionalTime(120000) then sleep for 100 secs : Service stopped after the 100 seconds.
RequestAdditionalTime(300000) then sleep for 240 secs : SCM error "Service did not respond in timely fashion"
Don't see any mention of maximum value but there's obviously a difference. FWIW WaitToKillServiceTimeout was 300000 but I don't think that should be a factor in OnStop ?