Running Programs at Startup
The Run and RunOnce subkeys are useful for running programs automatically when the computer starts or when users log on to the computer. You learn about these keys in Chapter 18, “Fixing Common IT Problems.” These keys are a handy way to deploy software that requires administrator privileges.
The Run and RunOnce keys are in two different locations. First, you see these subkeys in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion. Commands that appear in this branch run when any user logs on to the computer. You also see these subkeys in HKCU\Software\Microsoft\Windows\CurrentVersion. Commands in this branch run after a specific user logs on to Windows. Windows also treats commands in Run differently than commands in RunOnce:
Windows runs the commands in this subkey every time a user logs on to the computer.
Windows runs the commands in this subkey once, and then removes the key from RunOnce after the command is completed successfully.
To add a command to Run or RunOnce in HKLM or HKCU, create a REG_SZ value that has an arbitrary but descriptive name. Put the command line you want to execute in the new value. For example, the Run key in HKCU has the value MSMSGS by default, and this value contains “C:\Program Files\Messenger\msmsgs.exe" /background, which runs Windows Messenger every time the user logs on to Windows. Although you might have occasion to add commands to the Run subkey, it's more common to remove commands from this subkey to prevent programs from running when you start or log on to Windows.