RunOnce vs Run

Jan 23, 2012 at 12:16 PM
Edited Jan 23, 2012 at 12:17 PM

I see that dotNetInstaller uses the Run Registry key to resume installation after a reboot rather than the RunOnce key.

This works fine on XP, but on Windows 7 the installer does not resume. The reason for this is explained in the following two articles:

According to Microsoft, applications that require elevated privileges are blocked from being started by the Run key, but can be started by the RunOnce key (albeit only next time an administrator logs in).

The decision to use Run rather than RunOnce in dotNetInstaller is evidently a deliberate one. I wondered what the reason is, and how other users of dotNetInstaller manage to get their installers to resume after a reboot on Windows 7?

Jan 30, 2012 at 4:32 PM

This has some deep history, notably that RunOnce is a Windows 7 thing I believe. I am sure if we dig this we'll find lots of bad reasons for this decision, so I'd be open to patches that let you specify where and how the bootstrapper should register itself for reboot.

Jan 31, 2012 at 5:42 PM

You can use the Run key with dni if you set your manifest to not run as administrator and the install to administrator_required=true, then when dni restarts you will get the auto elevation trigger if required. I think RunOnce (and the Start Menu) suffer similar issues to Run if you try to start a run as administrator program.

Feb 1, 2012 at 8:30 AM

Yes, changing the manifest to

requestedExecutionLevel level="asInvoker"
and DNI's configuration
does indeed work. DNI starts as a non-elevated process on reboot, and then immediately re-launches itself elevated (with the consequent UAC prompt to the user). This is the solution we decided upon for our project.

According to the Microsoft documentation, RunOnce is designed specifically for installers that require a reboot and does not suffer the same issue as Run for an elevated privilege process. This is explained in the second reference in my original post. I haven't actually tried it though.

We're just making our release now. If I have the opportunity in our next development cycle I might look at a patch to make DNI use RunOnce instead of Run. But I'm not promising anything (sorry).

Feb 1, 2012 at 8:33 AM

Just for reference, here's the MSDN docs: Developing Applications that Run at Logon on Windows Vista

Developing a Multi-Part Setup Application

Certain applications when executing setup may require a reboot to continue and complete the installation.

In such a case, the elevated application should write to the RunOnce registry key at: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce.

When the system reboots and a user in the Administrators group logs on, the application will launch, complete the installation and delete the entry from the RunOnce key without requiring the user to interact with a UAC elevation dialog box.

The application must inform the user that a user that is a member of the Administrators group must log on after the reboot. If a user other than one in the Administrators group logs on, the installation will be either incomplete or corrupt since the RunOnce key will not execute for the standard user.
Feb 1, 2012 at 6:15 PM

Last time I tried to use RunOnce I didn't think the user experience was very good. IIRC the install runs before the user is properly logged on (i.e. no taskbar) which looks odd and also means they can't use Windows until the install is finished. I would suggest that changing to use RunOnce should be optional. 

For info - I have just posted a patch which fixes and issue where the Run key wasn't deleted after a restart.

Feb 1, 2012 at 7:53 PM

I have just tried using RunOnce and I can confirm that the installer runs before the user is properly logged on. With Windows 7 you get a black background, no desktop, taskbar or start menu and this install runs like this. Once the install finishes the logon is completed.