Search code examples
windowsrunonce

Why is it bad to create entries under the RunOnce key from an application that launches from the RunOnce key?


Microsoft's documentation on the Run and RunOnce keys has some vague warnings that I can't actually find more detailed information about. These warnings are:

A program that is run from any of these keys should not write to the key during its execution because this will interfere with the execution of other programs registered under the key.

An application must not continually recreate entries under RunOnce because this will interfere with Windows Setup.

What actually happens in these two scenarios? I have an app that goes against both of these recommendations, i.e. it is launched from the RunOnce key and recreates it's own launch command under RunOnce before terminating. It has done so for years without problems, so I'd like to understand what the actual risk is before I dive in and try to replace this app. I am discounting the obvious risk that if the app crashes it won't necessarily reschedule itself. What other problems could I be creating for Windows?


Solution

  • Between Raymond Chen's comments and finding this question on StackOverflow, I think I now have an explanation for both warnings:

    1. From this question, it is possible to enter an infinite loop if a program run from a RunOnce key re-adds itself to the RunOnce key before all entries in the RunOnce key have been processed. In my case, the app that sparked my investigation doesn't write back to the RunOnce key immediately after starting, but rather a while later and obviously after Windows has processed the RunOnce key, so we never saw this bug.
    2. As Raymond Chen pointed out, Windows Setup tries not to upgrade Windows while an application is being installed. Since RunOnce is meant for running installers, always having an entry in RunOnce will fool Windows Setup into thinking there is an installation in progress, interfering with Windows upgrades.