Tuesday, November 13, 2007

My Web Windows Services Console

I've been thinking about working on a tiny web application to remotely start and stop Windows services via a browser and I finally stopped thinking and did something about it. It was remarkably simple with the GridView control and it took a little over fifteen minutes, including the time to chat via IM with a buddy.

I had to include the System.ServiceProcess assembly and calling the System.ServiceProcess.ServiceController.GetServices() method returned an array of System.ServiceProcess.ServiceController. Now, the GetServices method has an overload that takes a machine name but I haven't tried it yet. It probably needs either a Windows domain or some way to authenticate with the other machine - the former I don't have and the latter I can't be bothered with right now.

I added a Start/Stop button and it did actually effect the service, but I had to add an ASP.NET Button to act as a refresh button to actually see the new status of the service due to the time it takes to actually start/stop. I added a two second sleep and tested it against the Windows Time service but that didn't seem to work and I'm guessing I need a longer sleep time.

Anyway, that's as far as I'll build for my little web Windows Services console.

UPDATE: I decided to venture a little further and found the method ServiceController.WaitForStatus that takes in the desired status and timeout as parameters.

No comments: