Run\RunOnce\RunOnceEx are documented ways to automatically run certain tasks when system startup or a user logs in.


Run\RunOnce keys are documented here:


Run and RunOnce Registry Keys


RunOnceEx is documented here:


Syntax for the RunOnceEx Registry Key


Description of the RunOnceEx Registry Key


You can also specify RunOnce when install device drivers


KB 281820: INFO: Specifying RunOnce in Device INF Files;EN-US;Q281820


Be careful about RunOnce registry key: It may run before system restart.


According to KB 281829, RunOnce registry key will run in the following cases:


1. At the end of installation through InstallFromHinfSection even in the cases where you must restart the computer.

2. After the default processing of DIF_INSTALLDEVICE even if you must restart the computer (with the exception of server-side processing).

3. After the system has been restarted.


This means, RunOnce registry key entries may be executed immediately after a device driver installation, which may happen at any given time.


If your RunOnce entry needs to be executed after certain event, make sure you write the RunOnce registry key after the event, or if you cannot do so, use RunOnceEx. Otherwise you may experience random failures.