]
This material originally appeared in the November 1998 issue of Windows Developer's Journal (copyright 1998 Miller Freeman Inc.) and is reproduced here with permission of the publisher.
Windows 95, Windows 98, and Windows NT have a set of registry keys named "Run" and "RunOnce" located under
HKEY_LOCAL_MACHINE
\Software
\Microsoft
\Windows
\CurrentVersion
Every time a user logs in to the machine, Windows enumerates all values stored under "Run" and "RunOnce" and treats each value's data as a command. During login, Windows executes all commands listed under "Run". Windows also executes commands listed under "RunOnce", but deletes each registry value, so the command will not execute again during subsequent logins. You can use these keys to automate tasks during user login or to replace files that were in use during a previous session. However, there are a few quirks programmers should know about to avoid potential problems:
ShellExecuteEx() to invoke each command, which means
you can take advantage of file type associations (e.g., you could execute a
.txt file to run Notepad). In contrast, Windows 95 calls
CreateProcess(), which does not provide this functionality.
Windows 98 uses ShellExecuteEx for "Run" commands and
CreateProcess for "RunOnce" commands.
]