Run/RunOnce/RunOnceEx Registry Key


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
http://windowssdk.msdn.microsoft.com/en-us/library/ms723554.aspx

 

RunOnceEx is documented here:

 

Syntax for the RunOnceEx Registry Key
http://support.microsoft.com/default.aspx?kbid=232509

 

Description of the RunOnceEx Registry Key
http://support.microsoft.com/kb/310593

 

You can also specify RunOnce when install device drivers

 

KB 281820: INFO: Specifying RunOnce in Device INF Files
http://support.microsoft.com/default.aspx?scid=kb;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.

Comments (5)

  1. Tim says:

    Hi, I have a Fusion/SxS question.  Is it possible to create an activation context that probes more than one private directory?  I have DLLs with COM objects located in various directories and would like to use RegFree COM with them.  I can call CreateActCtx and ActivateActCtx on one DLL manifest and call CoCreateInstance, but how do I create a single context that encompasses different DLLs located in different directories?  i.e.

    c:Program FilesMyAppMyApp.exe

    c:HereFoo1DLL1.dll (COMObj1)

    c:ThereFoo2DLL2.dll (COMObj2)

  2. The official recommendation is one manifest per directory. I have never tried your scenario so I can’t tell.