I have written several posts about starting an application when a Windows CE device boots. These posts have been fairly popular, but there are still some questions. The how to posts include:
·         Windows CE: Starting an Application when the System Boots which covers information needed by both application developers and Platform Builder users.
·         Windows CE: Programmatically Setting Up an Application to Auto Start which covers writing an application that sets itself up to run when the system boots.
·         Windows CE: Automatically Start Application with Command Line Parameters which covers how to start an application and pass in command line arguments to it.
Here are some of the questions that I have received about starting applications when the system boots:
  • I added my application to HKEY_LOCAL_MACHINE\Init, but it doesn’t run when the system boots. I can run the application from Explorer. What is wrong?
This is not an uncommon problem. For this discussion, let’s assume that the application is where you put it and that you correctly added it to the Init key. The usual problem is that your application is dependent on something that is not yet ready. Starting an application as soon as the system boots is different than running it later. The application must ensure that the APIs that it needs are ready to be used and that the drivers and disks that it needs are ready.
To determine if an API is ready to be used, you can use IsAPIReady() but it is recommended that this function be replace with OpenEvent() and WaitForSingleObject(), or for Windows CE 6.0 and beyond WaitForAPIReady().
To determine if a disk is ready, you can use the example that wrote in Windows CE: Monitoring for Disk Insertion to add support for Startup folders or if you know the disk will be mounted you could loop waiting for FindFirstFile() to return success looking for the folder name of the disk.
  • I want to run my application from an SD Card of CF Card when the system boots, but it doesn’t start. What is wrong?
The problem here is that if the card isn’t mounted by the time that Filesys tries to launch the application, the application won’t load. The solution is to include an application that can run early and monitor for the card to be mounted, then run your application from SD.
  • I put my application in the \Windows folder, but it isn’t there when the system boots. What is wrong?
The problem here is that the \Windows folder is in RAM, so a reset or power loss will delete any files that you put into it. So now we need to look to see if your changes to the Init key persisted through the reset or power loss.   If it did, then there must be some persistent storage on the device, so figure out where that is and put your application there. If you do this, you may also need to change the system path which I covered in Windows CE: Setting the System Path.
If the system that you are using doesn’t have a persistent disk, then you really should pick a different system if you want to start an application when the system boots.
Copyright © 2009 – Bruce Eitman
All Rights Reserved