Run registry entries

Just some notes on using the Run and RunOnce registry entries in Windows

If you want to add a registry entry to run a .cmd, .bat or .exe file from a Run or RunOnce entry


HKML\Software\Microsoft\Windows\CurrentVersion\Run  or HKCU\Software\Microsoft\Windows\CurrentVersion\Run

you can use a full path such as  C:\Windows\Fred.cmd

However, it is good practice to use a system variable because the Windows folder may not always be C:\Windows. It may be C:\Windows.1 if the user has installed more than one copy or D:\Windows if the user is booting from a different disk.

In this case we can use a variable like %windir%\Fred.cmd instead.

However, the registry type must be REG_EXPAND_SZ = 2.  This ensure that any variables are expanded before execution (probably would have been too obvious if MS had called it REG_EXPAND_VARS !!!

If using an INF file, we need to use 0x00020000 - e.g.




Note: The INF files that are copied to %windir%\oemdir will not run if OemPreinstall=No is used in winnt.sif. This means registry entry and some other non-driver lines won't run in GUI mode. The INF files can be forced to re-run if you add an [OemInfFile] section and specify %SystemRoot%\xxx.inf (look in the folder to see what name the inf files end up as).

See here for more INF keys