Automatically Run an Application from a Storage Card
The autorun feature, which is part of the OS, enables Windows Mobile software to do the following:
Detect a storage card that has been inserted into a Windows Mobile device and automatically load a specified application from the storage card into active memory.
Detect removal of a storage card and instruct the application to perform cleanup and to remove itself from active memory.
Renaming any executable file to Autorun.exe causes it to launch automatically when the card is inserted into the device. The Autorun.exe file must be in a directory whose name coincides with the processor type value of the device. To take advantage of this feature, add the following file structure and file to a storage card:
\<processor type value>\autorun.exe
For example, the folder name 2577 signifies an ARM processor. This is the typical processor for a device running Pocket PC 2002 or later. For this processor, the file structure is as follows:
See SHGetAutoRunPathfor a list of applicable folder names for other processor models.
When a user inserts a storage card, the Windows Mobile software does the following:
Searches the root directory of the card for a directory named with the appropriate processor code for that device.
Searches this directory for the Autorun.exe file, and loads this file to the \Windows directory in main memory on the device.
Invokes the copy of Autorun.exe on the device, passing it the command-line argument
When the user removes the card, Windows Mobile does the following:
Invokes Autorun.exe, passing it the command-line argument
The software also detects whether a card is inserted, removed, or swapped while the power is off and takes appropriate action as soon as the device is turned on.
You can determine the source directory for the Autorun.exe file with the SHGetAutoRunPath function. A storage card must be inserted for this function to succeed, although Autorun.exe does not need to be present on the storage card. This function creates the directory path, based on the present processor and returns it as a string variable.
A game developer can store game binaries and data files on a storage card. The developer can then design the Autorun.exe file that adds registry settings and loads necessary files when the storage card is inserted into the device and removes these settings and files when the card is removed. If the game must retrieve its home path, SHGetAutoRunPath returns it in a string variable.
In an enterprise application, Autorun.exe can be used to deploy a custom software application and data to a large number of devices. Updates to the application can be distributed to remote employees on inexpensive, low-capacity storage cards that perform automatic and trouble-free installation when inserted into the devices.
If users must cold boot or replace their devices, they can insert a preprogrammed storage card that contains the application and data and turn their device on. The autorun feature then launches the Autorun.exe application and performs the programmed actions.