Writing Windows Services

I’m currently writing a Synchronisation Service for RedZebra Software. It synchronises information between Call2Field and k3 SysPro.

I was having a bit of trouble getting the MSI installer to register the service, so I thought I’d throw this post together in case it would help me if I forget again!

Microsoft have produced a tutorial for creating an Windows Service app and installer, it’s pretty foolproof, right up to the part where it says you might not need Custom Components (but you do, otherwise the program files get copied but the service isn’t registered), so don’t skip that bit!

Install, Start, Stop and Uninstall Windows Services using SC

SC is a very useful command for total manipulation of Windows Services, especially when you get past it’s quirky arguments.

  • Install a Windows Service with SC
    sc create "Service Name" binPath= "C:\Program Files\Whatever\Service.exe"

    Note: There’s a space between binPath= and the actual path – this catches a lot of people out!

  • Uninstall a Windows Service with SC
    sc delete "Service Name"
  • Start and Stop a Windows Service with SC
    sc start "Service Name"
    sc stop "Service Name"