You are on page 1of 9

Using RunOnceEx

Introduction
There are many ways to deploy custom settings to your unattended install, such as using cmdlines.txt, svcpack.inf, and GuiRunOnce. One method I'd like to highlight is using RunOnceEx. This method allies you to deploy settings at either the 13 min mark of setup or before the first logon.

How RunOnceEx works


RunOnceEx is a part of the Windows Desktop Update. It is run from this registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{89820200-ECBD-11cf-8B85-00AA005B4340}. Obviously, don't delete this key! The resources for RunOnceEx reside in iernonce.dll. If you wanted to, you could use a resource editor such as Resource Hacker to change the text and icon RunOnceEx uses. During setup the RunOnceEx key is only processed at the 13 min mark because of Outlook Express. The RunOnceEx key is run before cmdlines.txt is run. So if you use cmdlines.txt or svcpack.inf to import the runonceex settings they won't run until first logon.

PreReading
AaronXP has written a good guide on RunOnceEx here. This guide will focus on using .inf files. Syntax for the RunOnceEx Registry Key

Advantages and Disadvantages of using RunOnceEx


Pro: Looks more professional (see screenshot below) End user cannot cancel. If the pc is rebooted, any unprocessed commands are run. Cons: Command syntax is a little bit harder than usual.

What it looks like


Below is a picture of what you will see when RunOnceEx is run.

Example of RunOnceEx
This is an Example of a working RunOnceEx that I will use to illustrate how to use RunOnceEx. runonceex.inf [Version] Signature=$CHICAGO$ [DefaultInstall] AddReg = RunXP [XP] AddReg = RunXP [RunXP] ;http://support.microsoft.com/?kbid=232509 HKLM,"%RunOnceEx%\",Title,0,"Installing Applications" HKLM,"%RunOnceEx%\",Flags,0x00010001,20 HKLM,"%RunOnceEx%\install01",,,"Adobe Acrobat 6" HKLM,"%RunOnceEx%\install01",1,,"%10%\Apps\Adobe6\AdbeRdr60_enu_full.exe -p"""-s /v\"""/qn\""" HKLM,"%RunOnceEx%\install03",,,"Directx 9" HKLM,"%RunOnceEx%\install03",1,,"%10%\Apps\DX9\dxsetup.exe /OPK" HKLM,"%RunOnceEx%\install04",,,"Nero Burning Rom 6"

HKLM,"%RunOnceEx%\install04",1,,"%10%\Apps\Nero\nero60028.exe /silent /noreboot" HKLM,"%RunOnceEx%\install05",,,"Norton Antivirus Corp" HKLM,"%RunOnceEx%\install05",1,,"%10%\Apps\Norton\navclnt.exe /qn" HKLM,"%RunOnceEx%\install06",,,"R-Studio" HKLM,"%RunOnceEx%\install06",1,,"%10%\Apps\RStudio\rss.exe /Q:A" HKLM,"%RunOnceEx%\install07",,,"Raxco PerfectDisk" HKLM,"%RunOnceEx%\install07",1,,"%11%\msiexec.exe /i %10%\Apps\Raxco\Perfectdisk.msi /q" HKLM,"%RunOnceEx%\install08",,,"Winrar 3.20" HKLM,"%RunOnceEx%\install08",1,,"%10%\Apps\Winrar\silent /s" HKLM,"%RunOnceEx%\install09",,,"Windows Media Player 9.0" HKLM,"%RunOnceEx%\install09",1,,"%10%\Apps\WMP9\mpsetupedp.msi" HKLM,"%RunOnceEx%\install10",,,"Windows Support Tools" HKLM,"%RunOnceEx%\install10",1,,"%10%\Apps\SupTools\Suptools.msi /qb" HKLM,"%RunOnceEx%\ZZcleanup",,,"Cleaning up" HKLM,"%RunOnceEx%\ZZcleanup",1,,"%10%\Apps\cleanup.bat" HKLM,"%RunOnceEx%\ZZcleanup",2,,"%11%\cmd.exe /c rd /S /Q %10%\Apps" HKLM,"%RunOnceEx%\ZZcleanup",3,,"%11%\cmd.exe /c del /Q """%16409%\Nero StartSmart.lnk""" HKLM,"%RunOnceEx%\ZZcleanup",4,,"%11%\cmd.exe /c del /Q """%16409%\Adobe Reader 6.0.lnk""" HKLM,"%RunOnceEx%\ZZcleanup",5,,"%11%\cmd.exe /c del /Q """%16407%\PrintMe Internet Printing""" HKLM,"%RunOnceEx%\ZZcleanup",6,,"%11%\cmd.exe /c rd /S /Q """%16407%\PrintMe Internet Printing""" [Server2003] AddReg = Run2003 [Run2003] ;http://support.microsoft.com/?kbid=232509 HKLM,"%RunOnceEx%\",Title,0,"Installing Applications" HKLM,"%RunOnceEx%\",Flags,0x00010001,20 HKLM,"%RunOnceEx%\install01",,,"Adobe Acrobat 6" HKLM,"%RunOnceEx%\install01",1,,"%10%\Apps\Adobe6\AdbeRdr60_enu_full.exe -p"""-s /v\"""/qn\""" HKLM,"%RunOnceEx%\install03",,,"Directx 9" HKLM,"%RunOnceEx%\install03",1,,"%10%\Apps\DX9\dxsetup.exe /OPK" HKLM,"%RunOnceEx%\install07",,,"Raxco PerfectDisk" HKLM,"%RunOnceEx%\install07",1,,"%11%\msiexec.exe /i %10%\Apps\Raxco\Perfectdisk.msi /q" HKLM,"%RunOnceEx%\install08",,,"Winrar 3.20" HKLM,"%RunOnceEx%\install08",1,,"%10%\Apps\Winrar\silent /s" HKLM,"%RunOnceEx%\install09",,,"Configuring Server 2003" HKLM,"%RunOnceEx%\install09",1,,"%11%\rundll32 setupapi,InstallHinfSection

Post 128 %17%\runonceex.inf" HKLM,"%RunOnceEx%\ZZcleanup",,,"Cleaning up" HKLM,"%RunOnceEx%\ZZcleanup",1,,"%10%\Apps\cleanup.bat" HKLM,"%RunOnceEx%\ZZcleanup",2,,"%11%\cmd.exe /c rd /S /Q %10%\Apps" HKLM,"%RunOnceEx%\ZZcleanup",3,,"%11%\cmd.exe /c del /Q """%16409%\Adobe Reader 6.0.lnk""" HKLM,"%RunOnceEx%\ZZcleanup",5,,"%11%\cmd.exe /c del /Q """%16407%\PrintMe Internet Printing""" HKLM,"%RunOnceEx%\ZZcleanup",6,,"%11%\cmd.exe /c rd /S /Q """%16407%\PrintMe Internet Printing""" [Post] AddReg=13min [13min] ;Enable themes support HKLM,"System\CurrentControlSet\Services\Themes","Start",0x00010001,2 ;automatic ;Disable that stupid shutdown event tracker HKLM,"Software\Policies\Microsoft\Windows NT\Reliability","ShutdownReasonOn",0x00010001,"0" ;Disable Ctrl + Alt + Del to logon HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","DisableCAD",0x00010001,"1" ;Change screen saver timeout to 50 mins. HKCU,"Control Panel\Desktop","ScreenSaveTimeOut",0,"3000" ;Disable that stupid configure server wizard HKCU,"Software\Microsoft\Windows NT\CurrentVersion\Setup\Welcome","srvwiz",0x00010003,"0"

[Strings] RunOnceEx = "SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx" This inf I use for both XP and Server 2003. The advantage to having everything in 1 .inf is having everything in one place. It also saves space on the CD. The first thing to note is the order items are listed. RunOnceEx will run commands in alphabetical order. So it will run Install01 before Install02. It uses the old sorting method so I recommand using 01 instead of 1. The reason is because it will run Install10 before Install2. Another thing to note is that I used the same command names in each section. This way if I want to copy a section from XP to Server2003, I don't have conflicting names.

If you want to run an inf refer to install09. That command runs the [13min] section of this inf. The reason I did this is because some settings are reset at the end of setup. At the very end I have ZZcleanup. The reason I called it ZZcleanup is so it's always run last. I want it to run last so I don't run into problems such as programs still into memory. In this example, I use ZZcleanup to run a batch file, delete %windir%\Apps, and delete start menu items. One problem you'll run into with RunOnceEx is that it's picky with variables. Using an inf makes life easier because you can specify any folder using a DirId. Below is a list of DirId's taken from my install.inf. Dir Id's (thanks to gtaylor for the list) ; A DIRID can be one of the following values: -01, ; ; Value Destination Directory ; ; 01 SourceDrive:\pathname (the directory from which the INF file was installed) ; 10 Windows directory ; This is equivalent to %windir%. ; 11 System directory ; This is equivalent to %windir%\system32 for NT-based systems, ; and to %windir%\system for Windows 9x/Me. ; 12 Drivers directory ; This is equivalent to %windir%\system32\drivers for NTbased platforms, ; and to %windir%\system\IoSubsys on Windows 9x/Me platforms. ; 17 INF file directory ; 18 Help directory ; 20 Fonts directory ; 21 Viewers directory ; 23 Color directory (ICM) (not used for installing printer drivers) ; 24 Root directory of the system disk. ; This is the root directory of the disk on which Windows files are installed. ; For example, if dirid 10 is "C:\winnt", then dirid 24 is "C:\". ; 25 Shared directory ; 30 Root directory of the boot disk, also known as "ARC system partition," ; for NT-based systems. (This might or might not be the

same directory as ; the one represented by dirid 24.) ; 50 System directory for NT-based operating systems ; This is equivalent to %windir%\system (NT-based systems only). ; ; 51 Spool directory (not used for installing printer drivers see Printer Dirids) ; 52 Spool drivers directory (not used for installing printer drivers) ; 53 User profile directory ; 54 Directory where ntldr.exe and osloader.exe are located (NT-based systems only) ; 55 Print processors directory (not used for installing printer drivers) ; -1 Absolute path ; ; ; Value Shell Special Folder ; ; 16384 %userprofile%\Desktop ; 16386 %userprofile%\Start Menu\Programs ; 16389 %userprofile%\My Documents ; 16390 %userprofile%\Favorites ; 16391 %userprofile%\Start Menu\Programs\Startup ; 16392 %userprofile%\Recent ; 16393 %userprofile%\SendTo ; 16395 %userprofile%\Start Menu ; 16397 %userprofile%\My Documents\My Music ; 16398 %userprofile%\My Documents\My Videos ; 16400 %userprofile%\Desktop ; 16403 %userprofile%\NetHood ; 16404 C:\WINDOWS\Fonts ; 16405 %userprofile%\Templates ; 16406 %allusersprofile%\Start Menu ; 16407 %allusersprofile%\Start Menu\Programs ; 16408 %allusersprofile%\Start Menu\Programs\Startup ; 16409 %allusersprofile%\Desktop ; 16410 %userprofile%\Application Data ; 16411 %userprofile%\PrintHood ; 16412 %userprofile%\Local Settings\Application Data ; 16415 %allusersprofile%\Favorites ; 16416 %userprofile%\Local Settings\Temporary Internet Files ; 16417 %userprofile%\Cookies ; 16418 %userprofile%\Local Settings\History

; 16419 %allusersprofile%\Application Data ; 16420 System Root (C:\WINDOWS) ; 16421 C:\WINDOWS\System32 ; 16422 Program Files ; 16423 %userprofile%\My Documents\My Pictures ; 16424 %userprofile% ; 16425 C:\WINDOWS\System32 ; 16427 C:\Program Files\Common Files ; 16429 %allusersprofile%\Templates ; 16430 %allusersprofile%\Documents ; 16431 %allusersprofile%\Start Menu\Programs\Administrative Tools ; 16432 %userprofile%\Start Menu\Programs\Administrative Tools ; 16437 %allusersprofile%\Documents\My Music ; 16438 %allusersprofile%\Documents\My Pictures ; 16439 %allusersprofile%\Documents\My Videos ; 16440 C:\WINDOWS\resources ; 16441 C:\WINDOWS\resources\0409 ; 16443 %userprofile%\Local Settings\Application Data\Microsoft\CD Burning

How to integrate RunOnceEx settings


There are many ways to including RunOnceEx settings in your install. To keep things simple, I am only going to list my way. For other methods refer to Aaron's guide listed above, or search the forums for runonceex. First, create a file called runonceex.inf and put your runonceex settings in it. Then put it into your i386 folder. Edit txtsetup.sif and put this: runonceex.inf = 1,,,,,,,20,0,0 That way runonceex.inf will be copied to the %windir%\inf folder. Also add what's in bold below to txtsetup.sif: [HiveInfs.Fresh] AddReg = hivedef.inf,AddReg AddReg = hivesys.inf,AddReg AddReg = hivesft.inf,AddReg AddReg = hivecls.inf,AddReg AddReg = hiveusd.inf,AddReg AddReg = hivesxs.inf,AddReg

AddReg = dmreg.inf,DM.AddReg AddReg = new.inf,newhive Create new.inf and put it in your i386 folder. In txtsetup.sif add this line: new.inf = 1,,,,,,_x,,3,3 Also in dosnet.inf add these lines: d1,runonceex.inf d1,new.inf In new.inf put this if you're installing Server 2003: [Version] Signature=$CHICAGO$ [newhive] HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx",,0x00000012 HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx",Title,0x00000000,"Ap plying custom settings" HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx",Flags,0x00010001,0x0 0000020 HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\Infs",,,"Applying Inf's" HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\Infs",1,,"rundll32 setupapi,InstallHinfSection Server2003 128 ..\Windows\Inf\runonceex.inf" HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\Infs",2,,"rundll32 setupapi,InstallHinfSection DefaultInstall 128 ..\Windows\Inf\Install.inf" Or if you're installing XP put this in new.inf: [Version] Signature=$CHICAGO$ [newhive] HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx",,0x00000012 HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx",Title,0x00000000,"Ap plying custom settings" HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx",Flags,0x00010001,0x0 0000020 HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\Infs",,,"Applying Inf's" HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\Infs",1,,"rundll32 setupapi,InstallHinfSection XP 128 ..\Windows\Inf\runonceex.inf" HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\Infs",2,,"rundll32 setupapi,InstallHinfSection DefaultInstall 128 ..\Windows\Inf\Install.inf"

In both examples I included another inf - install.inf. This is just an example, you don't have to add this line. You can safely delete it if you want. To make it easier to understand I put the only thing changed in Bold. What will happen is at the end of text mode setup (the blue screen with the yellow bar), new.inf will be added to the registry. RunOnceEx is only run at the 13 min mark by outlook express (msoe50.inf). So at the 13 min mark of setup (xp or server 2003), runonceex.inf will be run. When it's run, it'll add more registry keys to runonceex. When setup is done and the first logon happens, runonceex will be run again, this is where the applications and such will be installed. I prefer installing programs at logon rather than the 13 min mark to avoid problems.

Running programs at the 13 min mark


In my above example, I chose to run install.inf at the 13 min mark, and install the apps at first logon. If you want everything to run at the 13 min mark, replace install.inf with your inf that has your settings. Or you could put your RunOnceEx settings in new.inf. Or you could use Runonce\Setup. Search the forums for more information on Runonce\Setup.

Testing RunOnceEx
Most people will test there RunOnceEx inf by restarting the computer or by running setup, but there is a far simplier way. Add the RunOnceEx registry entries, then run this command: rundll32.exe iernonce.dll,RunOnceExProcess Make sure you have the applications and such in the right folders though. For example, I put all my apps in $OEM$\$$\Apps which translates to %windir%\Apps during setup. So before running the above command i put my apps folder in %windir%.

More Information
Here are some good threads on RunOnceEx. Please use the forums first, PM me only if no one will help you. I mainly focus on using inf files, for information on using batch files refer to the links below to good threads.
v

You might also like