Let’s get started – starting up applications on Windows CE at boot time

Let’s get started – starting up applications on Windows CE at boot time

I’ve seen tons of questions on the newsgroups asked about how to startup apps at system init time on Windows CE.  I hope to answer %99 of them once and for all.  There’s a ton of options for startup, with different tradeoffs and platforms they’ll work on.

Regardless of which approach you take, be aware that if you get started this early at bootup then system services that you’re anticipating being ready may not be.  For instance, a compact flash based filesystem may take a few seconds after bootup before it’s available for use.  So if your application wants to read or write to a file right away, it should have some primitive polling mechanism where it tries say 10 times and waits a second between tries before giving up on accessing files.

Other stuff may not be up right after boot either, like the device may not have a DHCP address yet.  So program defensively as always, but just be aware that if some stuff fails the first time it doesn’t necessarily mean the system is hopeless – try again in a few more seconds.

I believe that PocketPC has a \windows\Startup menu folder that acts just like StartUp in the Windows XP Start menu.  If you’re on a PocketPC (or another CE platform that implements this) and you don’t really want to be a service (see (4) below), this is the easiest and probably best way.

Everything else assumes you’re on a standard Windows Embedded device that doesn’t have PocketPC shell to do nice things like start up apps for you.

The kernel decides which apps to load up and in which order by reading the values in HKLM\Init.  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcepb40/html/pbconconfiguringregistryfiletorunapplicationatstartup.asp has a good introduction to this.

Just remember to call the SignalStarted() API once you’re through with your initialization.  Also you should make your app depend on an executable that gets started late in the bootup process.  I would recommend depending on services.exe – i.e. services.exe must indicate it’s done starting up (when it calls SignalStarted()) before your app gets launched.

One drawback of option (2) is that you can’t pass command line arguments to apps.  Also you may want to delay your app startup a few seconds (say 10-20) if it’s not critical for system operation and you want to minimize the likelyhood you’ll have to poll for critical system services that aren’t started yet.  You could add an initial Sleep() of course, but if you want this app to be called at other times other than the boot process then you have to have a cmd line to specify the sleep option.

In CE 4.1 I added a sample called svcStart, which is a simple service loaded by services.exe with the sole purpose of starting up applications.  Note this isn’t officially tested or supported by MS.  However, I’ve used svcStart to startup apps in devices that went in MS executive’s houses.  So obviously I trust it enough to bet my career, if not my life, on it :).

To build it from Platform Builder, go to ‘build OS->open release directory’ and cd to %_WINCEROOT%\public\servers\sdk\samples\services\svcStart.  Then ‘build’ and run ‘sysgen -p servers svcstart.’  Add svcstart.dll to your image. You’ll need this registry to get the service started:


Each reg subkey under this represents a different application to be started. An example (from servers.reg) would be:
    “Args”=”register”    // command line arguments
    “Delay”=dword:4000   // delay time, in milliseconds, before the app will be started

Check out C code if you want to know more details.

You know that CE has a 32 process limit, right?  And that on just about any OS, processes are more expensive than threads.  In scenarios where you just need to do some quick initialization on system startup and then have your application quit, (1)-(3) are still fine options.

However if you’re writing a long-running system service, you should implement it as a DLL and have services.exe load it up on system initialization just like all the other built-in services (web server, telnet, UPNP, MSMQ, etc… depending on your platform).

Preaching services.exe is beyond what I plan on doing today (though soon I will), but at least understand services.exe and think about whether whatever you’re trying to start up is really a service after all.

Services.exe is available on CE 4.0 and above and PocketPC 2003 and above.  Docs are available at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceserv/html/cmconServicesexe.asp.

[10/19/2005 Update] Paul Tobey, one of our MVPs, wrote a very good newsgroup post walking through some common problems people have with starting apps at startup here.  It was written to a question regarding the HKLM\Init method, but many of the points are generically useful.

[Author: John Spaith]

Comments (7)

  1. Daniel Moth says:

    Looking forward to your services.exe preaching 🙂 Maybe you’ll share some magic for getting CF apps in there (as far as I know it is impossible)

  2. John Spaith says:

    Getting CF stuff in services.exe is impossible with CFv1, since native can’t instantiate managed directly. It may or may not be possible in CFv2.

    Even if it is possible, please don’t do it! CF wasn’t really meant to run in system proc’s like services.exe.

    In a future OS we may have a servicesCF.exe that enables long running CF services, but for now it’s not there.

  3. Daniel Moth says:

    Thanks for confirming. Reason I brought it up is it fits your criteria like a glove: Our custom CE-based device exists purely for our CF app to run on it 24×7. There is nothing else on the screen that the user can interact with and no other blind services offered by this networked display.


  4. Souhail says:

    How do you load a managed application on startup? if i decide not to load the shell. is that even possible?

  5. Parimal Javiya says:

    I was put my application in start up folder but then after i will restart my device then after .exe file is miss from start up folder. please suggest some solution.