views:

471

answers:

2

As the title says. I'd like for my application to start when the Windows Mobile device is turned on? I'm developing this app using the .NET Compact Framework 3.5 in C#. Thanks!

+7  A: 

To get your app to start, first we need to define "On".

There is "On soft reset": Here there are a couple choices. By far the easiest is to just put a shrtcut in the \Windows\Startup folder.

There is "On resume from sleep." This is a bit more complicated because you have to run something before that happens. The simplest mechanism here is to register your app with CeRunAppAtEvent with the NOTIFICATION_EVENT_WAKEUP event. You'll have to P/Invoke it, as there is no built-in managed method for it.

Edit: There is also "After hard reset". Some OEMs provide a mechanism to run an app or do some form of logic from a cold boot (Symbol for example). You'll have to check with the device OEM's docs for how this would work.

ctacke
Is there any specific way to put a shortcut into the startup folder? I analyzed the files that were there, and tried to create a new one pointing to a random app on the phone, but on startup, it gave me an error.
BFree
There are two ways via code: manually creating the file, or P/Invoking SHCreateShortcut: http://pinvoke.net/default.aspx/coredll/SHCreateShortcut.html
ctacke
+1  A: 

While the Startup folder certainly works, you might encounter problems depending on your configuration when your application requires other items (applications, drivers, hardware, ..) to be started and up and running first. I have developed for devices with a CF storage card where the CF card needed a couple of seconds after bootup to mount and be available, so one can not autostart an application sitting on that CF card immediately after a reset, thus the Startup folder solution failed. In that case you might want to look into the Launchxx entries in the registry that allow you more control about the starting order: http://msdn.microsoft.com/en-us/library/aa915408.aspx

Timo
The HKLM\Init solution, unfortunately, often fails for CF apps because it will try to launch your app before the required APIs for the CF itself are not yet loaded.
ctacke