A Service-Monitor Gadget for IIS and SQL-Server

Friday, 29 January 2010 18:16 by Tom Gröger


This Gadget for Windows Vista or Windows 7 gives your control over Windows Services like IIS/W3SVC or MSSQLServer. You can see if the Services are running, stop or restart them.

One strange thing that always hits me when I am fighting deadlines is that the closer they come the more I let myself drift away to spend time on some other non-important projects. I am sure that every programmer knows about it ..
Every now and then I give up to they call and instead of getting important things done I spend some time on something that I always wanted to do. This little gadget is the fruit of one of those fits of procrastination:

ServiceMonitor

What is it good for ?


My Development machine runs under Windows Vista using a full blown IIS7 and SQL-Server. While I use both for my daily work I don’t want to have them running always. so I changed the configuration for the W3SVC and MSSQLServer Services from automatic to manual start and wrote me a batch file that starts the Services on the first run and stops them on the second run. That kind of worked but it was awfully slow and often I forgot if the Services where already running and stopped them instead of starting them.

Ok, one of those busy days I had enough of this crutch and thought it would be nice to have a little gadget that shows me the current state of my IIS and SQL-Server and allows me to start or stop the Services.
What sounded so easy finally took me more than 2 days to realize - but it was worth it and beside that, it was a lot of fun.

 

How it works.


Gadget programming is actually quite easy and straight forward, but has some peculiarities. one of my first step was to download a Visual Studio Gadget Template which gave me a basic overview about the structure of a gadget. A few researches on the Net revealed that some WMI Scripting and a little HTML should do the trick .. well yeah, sort of. The first problem was to find the gadget folder so that I could work on the gadget.html file itself instead of re-installing the gadget every time.  Here it is:

C:\Users\YOUR_USERNAME\AppData\Local\Microsoft\Windows Sidebar\Gadgets


The second problem was more technical: Using WMI it is very easy to connect to a WMI Server and get access to the Services, but the html display is not updated immediately when you write to it. My first attempt was to request the current state of all registered Services in a loop and write the output into a table cell until the Serive is either running or stopped. Unfortunatly the IE Page did not reflect any changes, all I got was the first state ( while entering the loop ) and the exit state. Rats!

Now in a regular Windows Script you can simply use WScript.Sleep() to release a time slot and give the Browser page some time to refresh the display, but Windows gadgets run as HTML Applications (hta) and WScript.Sleep or WScript.Echo are properties of the WScript object, which can’t be created. Instead, the WScript object is automatically created - and only created - when you run a Windows Script Host (that is, WScript.exe or CScript.exe), not if you start a hta gadget.
Luckily there is a workaround for this problem using window.setTimeout to mimik WScript.Sleep, so instead of running in a closed loop we merely use setTimeout and recursive calls, and that lets Windows properly update our little Gadget display.

 

Installing the Gadget


The last hurdle to take was to create some kind of installation package – I thought.

In fact Microsoft was very very smart here, all you need to do is to pack all files of a gadget into a ZIP file and then rename the .zip extension to .gadget ! To install the gadget on your machine, simply double-click on the gadget archive and it installs itself in your gadget folder. Now that was easy, wasn't it ?

To use it, simply click on the Start and Stop buttons to start and stop the Services, and click on the header to refresh the Display - I did not want to have a timer running that constantly request the Service State.
You can add or remove Services on your own demand, take a look into gadget.html, all Services are declared inside the .Init() method.

Hope some of you will find this useful, enjoy, and let me know when you extend it !

 

Resources:


 

  , , ,
  HTML | IIS | SQL
  E-mail | del.icio.us | Permalink | Comments (4) | Comment RSSRSS comment feed

Comments

Nick Netherlands Nick
schrieb am Wednesday, February 17, 2010 3:25:37 PM |
Tom, within the zip file you need to move the content of the ServiceMonitor.gadget folder one level up (in to the root of the zip file) and then rename the .zip to .gadget.

Regards
Tom Gröger Germany Tom Gröger
schrieb am Wednesday, February 17, 2010 5:39:46 PM |
Hi Nick,

Thanks for your comment,

I have wrapped the zip/gadget file into another zip file because some Firewalls will not allow you to download a *.gadget file, nor let you send it by email.
Just download it, open/extract it, and double click on the gadget file, and it should install itself

Best regards from Husen,
Tom Gröger / TomSoft
Techie Norway Techie
schrieb am Tuesday, June 29, 2010 2:05:12 PM |
Hi Nick!

I'v tried installing your gadget on a win 7 32 bit os, but it does not seem to complete. No gadget is added. Do you have any known problems for this gadget regarding installation?


Best regards,

A techie from Norway
Tom Gröger Tom Gröger
schrieb am Tuesday, June 29, 2010 3:02:18 PM |
HI Techie,

It's Tom, not Nick <g>

No problems reported so far .. just rename the archive from .zip to *.gadget and doubleclick on it, that should install the Gadget into your
C:\Users\userName\AppData\Local\Microsoft\Windows Sidebar\Gadgets\ Folder ..

You can also extract the Gadget into that folder manually, if that doesn't work.

Best regards from Husen,
Tom Gröger / TomSoft