Windows CE: How to start an application when system boots

There are two ways in which you can achieve this task, Each one has its own pros and cons.

1. Registry: 

All the applications which are present inside HKLM/Init Registry will be started when the system boots. The values you have to use are LaunchXX and DependXX, where XX are numbers, example Launch62 and Depend62. This is the same we will be using for starting applications like Device Manager, Services Manager and Explorer Shell.

LaunchXX is a string value.Set the value of LaunchXX to name of your application
Eg: "Launch90"="Subproject2.exe"

DependXX is a hex value. The XX number must match the number that you used for LaunchXX. The value indicates which of the LaunchXX applications your application is dependent on.

Eg: "Depend90"=hex:14,00, 1e,00 indicates that your application is dependent on
Launch20(0x14 == 20) and Launch30(0x1e ==30).

If you use HKLM/Init to start your application, you should call SignalStarted() to tell the system that your application is running and ready. Failure to call SignalStarted() can cause other applications to not be started

An application that is launched through the registry gets its launch number(90 in this case) passed as a command line parameter { this is passed as a string, not as a number. But the SignalStarted API requires a DWORD as a parameter so you have to convert your String to word and then pass it to SignalStarted API.

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// Do some work here...
SignalStarted(_wtol(lpCmdLine));


Drawback: Processes launched through the HKLM/Init cannot be passed
additional command line arguments.


2. Startup Folder:

Anything that is present in the Startup Folder will be executed on Boot. But this way you cannot pass a command line parameters. But you can pass a shortcut file to your application in the startup folder and include the command line arguments in the shortcut fi le.
A shortcut file is a fi le with a LNK extension that contains:

<Number>#<command> <parameters>

Where: Number is the number of characters after the Pound Sign Command is the application that you want to run Parameters are the command line parameters to the application

So to start Application.exe and pass a string as an argument I have to create a shortcut file named Application.lnk and the contents of the file:

21#Application.exe Hello

References:

1. http://geekswithblogs.net/BruceEitman/archive/2008/12/12/windows-ce-automatically-start-application-with-command-line-parameters.aspx

2. http://blogs.msdn.com/b/cenet/archive/2004/12/03/274661.aspx

Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig