0

I have a Win32 service, that needs to run a .NET executable on service stop (for cleanup reasons). I recently discovered that the cleanup never happens on shutdown, because the process creation gets blocked by OS. Does anyone know a way to override this? Process, I am spawning is not invasive and should only run a fraction of a second.

galets
  • 17,802
  • 19
  • 72
  • 101
  • Take a look on the following link: http://stackoverflow.com/questions/848618/net-events-for-process-executable-start. It describes how you can subscribe to process events. – Klinger Jul 19 '11 at 19:59
  • @Klinger: I have absolutely no idea how is subscribing to process events going to help me – galets Jul 19 '11 at 22:44
  • 1
    I missed that you meant OS shutdown. The following link describes how to run scripts on startup/shutdown, not sure if this will help but you never know. http://www.tutorial5.com/content/view/157/47/ – Klinger Jul 19 '11 at 23:09
  • Also, the following SO question, that has no accepted answer, is similar to your question. http://stackoverflow.com/questions/5217246/how-to-delay-shutdown-and-run-a-process-in-window-service – Klinger Jul 19 '11 at 23:10
  • He says it's "impossible" and sugests the policy route, what is what that tutorial is about. There is also a policy to disable automatic closing of console and GUI apps. Follow link with instructions: http://www.technospot.net/blogs/how-to-turn-off-automatic-termination-of-applications-which-block-windows-shutdown/ – Klinger Jul 19 '11 at 23:25

1 Answers1

1

The only way I could find to do it was: pre-create a child process suspended, and them un-suspend it on shutdown.

galets
  • 17,802
  • 19
  • 72
  • 101