An explanation of, and the relationship between the Run, RunOnce, RunServices, RunServicesOnce and Startup
Many times we have been asked how these keys effect the operation of Windows, when they are loaded and in what order. The following information should provide you with a better understanding of these registry keys, their relationship to each other and to the Windows Startup folder.
These references apply to:
- Microsoft Windows 95
- Microsoft Windows 98
- Microsoft Windows Millennium Edition
- Microsoft Windows NT Server versions 3.51, 4.0
- Microsoft Windows NT Workstation versions 3.51, 4.0
- Microsoft Windows 2000 Advanced Server
- Microsoft Windows 2000 Server
- Microsoft Windows 2000 Professional
There are seven Run keys in the registry that enable programs to be run automatically:
- HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ RunOnce\Setup
*Note: The RunOnce key is not supported in Windows NT version 3.51.
Keys 1-4 are run each time a new user logs in.
Keys 5-6 are run in the background when the logon dialog box first appears, or at this stage of the boot process if there is no logon. These keys are for background services such as remote registry service and are run only once per boot.
Key 7 is run as part of Setup’s first-boot activities, or after you use the Add/Remove Programs Wizard.
Under each of these keys is a series of values. The values are used to allow multiple sub-entries to exist without one overwriting another.
The data value for a particular key is a command line. By default, Run keys are ignored in Safe mode. For keys 3-4, the value name can be prefixed with an exclamation point to defer deletion of the value until after the command has been completed.
For keys 3, 4, and 6, the value is deleted before the command line is run unless overridden as noted above. As a result, if a RunOnce operation fails to run properly, the component that failed will not be asked to run again the next time you start the computer.
Key 7 is used only by Setup. This key displays the progress dialog box as the keys are run one at a time. For key 7, the name of the value is the name that is displayed in the dialog box.
Key Load Order:
Under Windows 95 and Windows 98, where all keys are supported, the keys are loaded in the following order:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run StartUp Folder
With the exception of the HKEY_LOCAL_MACHINE\…\RunOnce key, all keys and their entries are loaded asynchronously. Therefore, all entries in the RunServices and RunServicesOnce keys can potentially run at the same time.
Entries in the HKEY_LOCAL_MACHINE\…\RunOnce key are loaded synchronously in the order they were added to the RunOnce key. Note: This is not necessarily the order in which these entries are displayed by the Registry Editor.
Since the HKEY_LOCAL_MACHINE\…\RunOnce key is loaded synchronously, all of its entries must finish loading before the HKEY_LOCAL_MACHINE\…\Run, HKEY_CURRENT_USER\…\Run, HKEY_CURRENT_USER\…\RunOnce, and Startup Folder entries can be loaded.
The RunServicesOnce and RunServices keys are loaded before the user logs into Windows 9x. Because these two keys run asynchronously with the Logon dialog box, they can continue to run after the user has logged on. However, since HKEY_LOCAL_MACHINE\…\RunOnce must load synchronously, its entries will not begin loading until after the RunServicesOnce and RunServices keys have finished loading.
Because of different system configurations, such as that of a computer that has been configured to automatically log on, any application that is dependant upon other applications that are executed under these keys being or having completed, must be prepared to wait until these applications have completed fully. Other than this exception, the above applies to Windows NT 4.0 and Windows 2000 as well.
The RunOnceEx Registry Key
Microsoft Windows 98 and Microsoft Windows Millennium Edition only!
RunOnceEx has the following features:
- Status – A dialog box that is displayed while the items contained in the registry key are being processed. The entries to be processed are grouped into sections with the dialog box highlighting the current section that is being processed. The status dialog box feature can be disabled.
- Performance – The majority of the commands contained in the Run and RunOnce registry keys involve the creation of separate processes, which is inefficient. The RunOnceEx registry key does not create separate processes, and also supports a dependency list of DLLs that remain loaded while either all, or some, of the sections are being processed.
- Error Handling – If an exception occurs while calling a function in a DLL, the exception is caught and an error dialog box is displayed to the user. You can suppress this error dialog box by using a flag in the RunOnceEx registry key, or you can also set a flag to enable log errors and execution of the RunOnceEx registry key.
- Deterministic – The RunOnceEx registry key sorts the entries and sections alphabetically to force a deterministic order.