## The AUTOLAUNCH Sample

The AUTOLAUNCH Sample accompanies Chapter 14 and illustrates how to launch an application automatically upon device attachment.

The sample includes four components:

- AUTOLAUNCH.EXE and ALNCH98.EXE (AutoLaunch subdirectory) are user-mode service modules for Windows XP and Windows 98/Me, respectively.
- TSTLNCH.SYS (SYS subdirectory) is a WDM driver for a non-existent hardware device.
- ALTEST.EXE (ALTEST subdirectory) is a Win32 application that will be invoked automatically whenever a new TSTLNCH device is detected.
- STARTSERVICE.DLL (STARTSERVICE subdirectory) is a DLL for use during Windows XP installations in order to get the AUTOLAUNCH service running the very first time.

### Building AUTOLAUNCH

To build TSTLNCH.SYS, follow the general instructions for building a WDM sample. The Microsoft Visual C++ project file is named TSTLNCH.DSP in the SYS subdirectory.

To build the other components, follow the general instructions for building user-mode programs. The Microsoft Visual C++ project files are named AUTOLAUNCH.DSP, ALTEST.DSP, and STARTSERVICE.DSP in the AUTOLAUNCH, ALTEST, and STARTSERVICE subdirectories, respectively.

The AUTOLAUNCH project contains subprojects for the Windows XP service and the Windows 98/Me pseudo-service. Don't forget to build both subprojects.

### Testing AUTOLAUNCH

Install the TSTLNCH "device." Follow the general instructions for using FastInst in Windows XP or Windows 98/Me. The INF file is named SYS\TSTLNCH.INF.

Installing the TSTLNCH device automatically starts the AUTOLAUNCH or ALNCH98 service, which in turn automatically invokes ALTEST. You should expect to see a dialog box on the screen indicating the automatic invocation of ALTEST.

To prevent the AUTOLAUNCH service from running in this and future sessions of Windows XP, open a command prompt and issue these two commands:

C:\>net stop autolaunch
C:\>autolaunch -unregister

To prevent the ALNCH98 applet from running in this and future sessions of Windows 98/Me, follow this procedure:

1. Right-click on the ALNCH98 icon in the icon tray. Select the Close choice and answer the ensuing dialog question in the affirmative.
2. Remove the entry named AutoLaunchService from the registry key HKEY_LOCAL_MACHINE\ Software\Microsoft\Windows\CurrentVersion\Run".

### Redistributing AUTOLAUNCH

AUTOLAUNCH is an exception to the blanket license to use the sample programs for this book. The author will grant a royalty-free license to anyone to redistribute AUTOLAUNCH as part of a WDM driver package. The license will, however, include conditions designed to insure the consistency and quality of AUTOLAUNCH on end user machines. Send e-mail to waltoney@oneysoft.com for information about obtaining this conditional license.

### What to look for

The interesting part of this sample is actually the user-mode code in AutoLaunch.cpp (AutoLaunch directory) that waits for enablement of the AUTOLAUNCH device interface.