marc_s
marc_s

Reputation: 755177

Be notified of an IIS Reset?

We have a system with a web app and a bunch of Windows Services doing some background work.

Whenever we need to make a more substantial change to the system, we end up having to issue an IIS Reset, and then manually restart all relevant Windows services.

Is there any way at all to be notified of such IISReset events in C# code, so that our Windows Services could restart themselves, whenever they detect such an IISReset command being executed?

Thanks! Marc

Upvotes: 2

Views: 2018

Answers (3)

TygerKrash
TygerKrash

Reputation: 1382

Agree with Nebakanezer, you may need to stop the service first though.

  • Option 1

NET STOP "SERVICE NAME"
NET START "SERVICE NAME"

  • Option 2

What about deploying a dummy asp.net app to the IIS server, then you can detect the application starting which should only happen on an IISReset and trigger the stop and restart of the services? I'm not sure if IIS has a tightened security model that will allow you to do thinks like stop services or trigger a batch file to do same but it's worth a try.

  • Option 3

If thats not an option for whatever reason, you could pull something together that monitors the IIS logs, I believe they log IIS resets.

Upvotes: 1

Irwin
Irwin

Reputation: 12829

You could also plug into Windows Instrumentation with you own custom Windows Query Language expression. I've never used it for IIS directly, but I expect that there would be objects you can listen to, which lets you be aware of such changes. You can check this out : http://www.csharphelp.com/archives2/archive334.html as a starting point for research.

Upvotes: 1

Mark Sherretta
Mark Sherretta

Reputation: 10230

Couldn't you just write a batch file to call IIS Reset and then restart the Windows Services?

I think the way to start a Windows Service is:

NET START "SERVICE NAME"

Upvotes: 1

Related Questions