The Pocket PC has a feature that can automatically launch an application when any new external storage is detected such as the insertion of a CompactFlash or Secure Digital card. This feature is typically used to provide an auto-install feature for software. However, there is no reason the application launched has to be an installation program.

When the shell detects that a storage card has been inserted, it looks in the root directory of that card for a directory with a specific name. If that directory exists and contains an application named autorun.exe, the application is first copied to the \windows directory, and then launched with a command line string install. When the card is removed, the copy of autorun in the \windows directory is again launched, this time with a command line of uninstall.

The directory that the Pocket PC searches for depends on the type of CPU in the device because an application must be compiled specifically for a CPU. The autorun directory names match the CPU type value returned from the GetSystemInfo function. The following list shows the values for a few of the more popular CPUs. All the CPU values are defined in Winnt.h.

MIPS (41xx series and 3910) 4000
SH3 10003
SH4 10005
StrongARM 2577
XScale 1824

When autorun.exe is launched, it might need to know which directory it was copied from on the storage card. The application can't use GetModuleFileName because it was copied and launched from the \windows directory. To determine the fully specified autorun path, an application can call

BOOL SHGetAutoRunPath (LPTSTR pAutoRunPath);

The single parameter is the address of a TCHAR buffer of at least MAX_PATH characters. The function will fail if no storage card is found. If a card is inserted, the function returns the expected autorun directory whether or not the actual folder exists on the storage card. For example, for a system with a StrongARM CPU and an Autorun.exe file in the appropriate directory, the directory returned is \storage card\2577\autorun.exe.

SHGetAutoRunPath can optionally be supported by systems based on Windows CE .NET 4.2 or later. However, the Explorer shell does not automatically launch applications from storage cards. An OEM could easily add this feature if needed.

This topic is from Programming Microsoft Windows CE, Third Edition, by Douglas Boling, published by Microsoft Press. © 2003 by Douglas McConnaughey Boling. Reprinted here by permission of the author.