QA: How can I write application what will be run every time the device is switched on?

Vassili Philippov (vasja@spbteam.com), July 23, 2001.

Question

I want my application to be active every time when the device is switched on (after soft reset or after wake up). Like the default iPAQ password application. How can I do it?

Answer

Two different activations (start up after soft reset and wake up) should be handled in different ways.

Run after soft reset

Place a shortcut to your application into \Windows\AutoStart folder and this application will be run every time just after the shell is started. Plase note that this folder is language depended. So you should use use SHGetSpecialFolderPath function with CSIDL_STARTUP parameter to get actual folder name on the device. Here is a sample code:

CString strProgramPath = _T("\"\\MyApp.exe\""); TCHAR szStartupFolderPath[MAX_PATH]; ::SHGetSpecialFolderPath(NULL, szStartupFolderPath, CSIDL_STARTUP, FALSE); CString strLinkPath = CString(szStartupFolderPath) + _T("\\MyApp.lnk"); ::SHCreateShortcut((LPTSTR)(LPCTSTR)strLinkPath, (LPTSTR)(LPCTSTR)strProgramPath);

Run after wake up

You should call CeRunAppAtEvent function with NOTIFICATION_EVENT_WAKEUP as the second parameter and path to your executable as the first parameter. Then your application will be called every time after wake up.

Here is a sample code that registers the application that it will be run every time the device is reset:

CeRunAppAtEvent(_T("\\MyApp.exe"), NOTIFICATION_EVENT_WAKEUP);

If you need to make your application the only application that can run on the deviuce that will start automatically and cannot be switched off then you can use Spb Kiosk Engine.

Related resources: