how to cancel service questions, again

Mar 30, 2009 at 6:01 PM

I followed the example to implement some simple program:

namespace ServiceConsoleTest
    class Service: ServiceApplication
        private static Service service = new Service();
        public const int WM_TIME_TestSERVICE = WM_USER + 5020;
        public Service()
            this.ServiceGuid = new Guid("{823761F0-4CED-4e3f-87AF-1933CF7556F4}");
            this.ServiceName = "Test Service";
            this.ServiceStartType = ServiceStartType.Automatic;

        public override void Start()
            this.ServiceState = ServiceState.Starting;


        public static Service GetInstance()
            return service;

namespace ServiceConsoleTest
    class ConsoleServiceTest
        static void Main(string[] args)

This program does nothing but run. I have two questions.

1) how to delete from registry file, I open Windows CE Remote Registry Editor->HKEY_LOCAL_MACHINE->Software->ManagedServices, and find the GUID I used in the program. I delete the whole ManagedServices folder, and also delete the application folder in mobile device. When I restart the mobile device, reconnect the registry, the ManagedServices and my program are still in the registry file. How can I delete them forever.

2) My second question is about the start function. Will the service program start with mobile device? I mean the service program will start with mobile devices start. If the mobile deveices become idle or sleeping, will the service still running? If we use warming start to restart the device, will the service restart or keep running? If user use coldstart, I think the service should restart.

Thank you very much
Mar 31, 2009 at 6:41 AM
Edited Mar 31, 2009 at 6:43 AM

sure, the service does nething than run. This is true - and this is what a service is dedicated to. If you have a an application started via Application.Run(...) it doesn't do anything than just run. This is the purpose. ;-)

According your questions.

1) Using the function this.Register() does the registration in the registry. This is optional and not mandatory. If you don't want it to appear in the Registry at all, just leave that line of code away. If you want to delete it afterwards, call this.Unregister() and the registry entries will disappear as well.
Be aware of, that if you haven't registered a service within the registry, the autorun feature won't be available...

2) No - the service doesn't start with the system directly. But it is possible to do.
Therefore you need to do a few steps.
  • Set this.ServiceStartType = ServiceStartType.Automatic; (you did that already)
  • Register your service with this.Register() (you did that already).
  • Install the ManagedServicesInstaller.CAB from the Binary Only Archive from the Releases Tab.
The last step is the most important one.
This CAB File includes a small application which is registered within HKLM\Init and is started during the startup of the system.
The included utility walks through the registry and looks for the keys below HKEY_LOCAL_MACHINE\Software\ManagedServices. If there are keys available it looks if a registered service has set the ServiceStartType to Automatic. If true the according registered Executable is started.
The services get started during a warming start. a cold start can't be supported, as the Launcher isn't part of the OS ROM. The last one isn't "possible". Then you shall prevent the user from coldstart, which isn't possible as well.
If you have a started service already it is still running, whether the app goes to sleep or becomes idle. (Well, in fact it is paused like any other application as well, as it isn't any system service).

Cheers, Peter