WindowsCE:Autorun
The autorun feature, which is part of the OS, enables Windows Mobile software to:
- Detect a storage card that has been inserted into a Windows Mobile-based device and automatically load a specified application from the storage card into active memory.
- Detect removal of the storage card and to instruct the application to perform cleanup and to remove itself from active memory.
Renaming any executable file to Autorun.exe will make it launch automatically when the card is inserted into the device. The autorun.exe file must be in an appropriately named folder that coincides with the processor in the device. To take advantage of this feature, add the following directory structure and file to a storage card:
- Note: The folder name 2577 signifies an ARM processor. This is the typical processor for a Pocket PC running Windows Mobile software version 2002 or later. See SHGetAutoRunPath for a list of applicable folder names for other processor models.
When a user inserts a storage card, the Windows Mobile software:
- 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
- The shell invokes the copy of autorun.exe on the device, passing it the command-line argument "install"
When the user removes the card, the shell invokes autorun.exe, passing it the command-line argument "uninstall". The software also detects whether a card is inserted, removed, or swapped while power is off and takes appropriate action as soon as the device is turned on.
Programmers can determine the source directory for the autorun.exe file by using 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 will create the directory path based on the present processor and return it as a string variable.