We help IT Professionals succeed at work.

How to Make Registry's RunOnce Command Wait?

Hi all,

I am writing an installation script in Wise InstallMaster to install MSDE 2000/SQL Server 2000 to a client's machine.

Here's the problem.  I have to use Windows Installer to install MSDE 2000.  In the script I execute the Windows Installer file, then I set a registry key in teh script to use the RunOnce functionality to execute a VB application I wrote that uses SQLDMO to install MSDE 2000 using Windows Installer after a forced reboot of the system.

The problem is that upon the reboot after installing Windows Installer Windows shows the Updating User Settings dialog box, and the RunOnce registry command is executed before the Updating User Settings are actually complete.

This causes my VB application to try to install MSDE 2000 before the actual Windows Installer files are able to be used.

I have tried using SLEEP in the VB app for 60 seconds, but that doesn't work, because it seems that the Updating Seconds routine stops and doesn't continue until the SLEEP is finished.

Does anyone have any ideas of how I can get the RunOnce Registry command to NOT execute until AFTER the Updating Settings dialog box finishes updating the Windows Installer setup?

I will give an A and 300 points to anyone who can give me a way to do this.

Watch Question

It depends on which RunOnce key you are setting.  The following is the order in which they are run at startup (for additional info on the order check out - http://support.microsoft.com/support/kb/articles/Q179/3/65.ASP):

<Logon Prompt>

StartUp Folder


You need to check where Windows Installer is being placed to run at startup.  It could be in the Startup Folder or later.  If you add your RunOnce key to the latest running one, under HKEY_CURRENT_USER, that will probably work and that your key is added after the Windows Installer item.

If Windows Installer is also placed there, try using RunOnceEx, which give you more control in the order in which items are run.

Use <Run> key instead - it executes AFTER all updates. You can use any other key to check if installation complete:
If GetSetting("Myapp","MyKey","AlreadyInstall", 0) Then
   RegDelete "....\Run\MyApp" 'Remove run key
   Exit Sub
'   Your Installation code
End if



'   Your Installation code
   SaveSettings "Myapp","MyKey","AlreadyInstall", 1
End if


Okay, DarthPedro, I changed my keys to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce and it doesn't work.

Let me explain better.  I run a Wise script to load Windows Installer and in that script it set the RunOnce setting for a second Wise script to run after the reboot.

Windows installer runs fine and the system reboots.  What I needed was the second script to run AFTER the reboot.

It doesn't matter where Windows Installer was loaded.  My problem was the Updating User Settings was interfering with the RunOnce settings, because it didn't wait for the settings update to finish.

I tried the key above hoping that it would wait fix it, but this setting did nothing.

My run once setting is HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce and the value is C:\MSDE\SQLScriptSetup.exe

This is strange because I originally had it under HKEY_LOCAL_MACHINE, where it did work, but like I said before the Updating User Settings stepped on it.

Any suggestions?

Here is order in which *Run* keys work (MSDN article is incomplete, this is my own tests):
1. HKLM\RunServiceOnce,HKLM\RunService 'w95/98/ME
2. HKLM\RunOnce
3. Windows Logon Input box (previous keys may still executed in BackGround)
4. HKCU\RunServiceOnce,HKLM\RunService 'w95/98/ME
5. HKCU\RunOnce
6. System updates performed (previous keys may still executed in BackGround).
7. Windows Shell loading - only after #6 finished
8. HKLM\Run, HKCU\Run executed - only after #7 finished




I finally got it to work.  What was happening was Wise Installer was creating an additional registry key.  Windows was reading the first key, where the Default value had nothing set and it was ignoring the second key.

I added a command to the script to delete the original key and it worked fine.

Thanks everyone for all our help!