got net?

Kevin Hazzard's Brain Spigot

About the author

Welcome to Kevin Hazzard's blog.
E-mail me Send mail

Recent posts

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Service Toggler Source Code

I'm very active in the User Group community so I do a lot of presentations. I wrote a quick and dirty application called ToggleService which lets me start or stop a Windows Service in a visual way. The picture above shows three screen shots side by side. On the left, you see my application as it queries the service called SQL Server (KATMAI) in the stopped state as indicated by the red light bulb. After clicking the Start button, the state transitions which shows the middle screen with the yellow light bulb. After a few seconds the service goes into the started state as indicated by the green light bulb on the right. I wrote this application to give my User Group attendees some visual feedback whenever I needed to start or stop a service during a presentation. It's very effective for that. So effective, in fact, that many people have asked me for the source code.

One important note: when you create a shortcut for this application, you must pass the long or short name of the service to ToggleService.exe on the command line. You can see the long service names in the Services Control Panel applet. In the case of the screen shot above, I found "SQL Server (KATMAI)" as the long name and passed it to the ToggleService.exe application on the command line. To find the short name of a service, you can use the command line service controller like this:

sc \\machineName GetKeyName "SQL Server (KATMAI)"

Of course, you must substitute your own machine name and the long name of the service that your querying for. This will produce output something like this:

C:\>sc \\machineName GetKeyName "SQL Server (KATMAI)"
[SC] GetServiceKeyName SUCCESS
Name = MSSQL$KATMAI

So, to toggle the SQL Server instance on my computer in which I'm interested, I could pass either of the following arguments to ToggleService.exe:

  • "SQL Server (KATMAI)"
  • MSSQL$KATMAI

You might observe at this point that the SC.EXE utility which I used to discover the short name of my service could have been used to start and stop the service during my presentations. Yes, that's true. But the little GUI I built is more colorful and exciting. You have to sell the sizzle and the steak, right? Anyway, the C# source code attached below requires Visual Studio 2008. There's nothing special about it but since so many people have asked for it, I thought I'd oblige. Enjoy!

Source code for Kevin Hazzard's ToggleService Utility (26.73 kb)


Tags:
Categories: C# | Fun | Pres Skills
Posted by kevin on Sunday, May 17, 2009 10:05 PM
Permalink | Comments (1) | Post RSSRSS comment feed

Comments

fun.dailynewsabout.com

Monday, May 18, 2009 12:00 AM

pingback

Pingback from fun.dailynewsabout.com

Daily News About Fun :  A few links about Fun - Sunday, 17 May 2009 20:53

Comments are closed