George King
Active Member
- Messages
- 440
- Reaction score
- 186
This tutorial helps you to create perfect post setup for Windows 7 - 10 setup media
What you can easily install using this tutorial?
1) Microsoft Office
2) Windows or Office updates (MSU / CAB / MSP)
3) Your own applications with predefined switch
4) Apply registry tweaks
5) Certificates CER files
6) Custom scripts - PS1 / CMD / BAT
Every installation steps are run before user logon after OOBE, this mean User Account is already created so all applications and registry tweaks should be installed without problem
We are going to use RunOnceEx method as its most comfortable and suitable way because it is inbox Windows component. RunOnceEx is really old but still working method as part of iernonce.dll + iernonce.dll.mui + IEAdvpack.dll (This file exist from Internet Explorer 9+, so doesn't exist in non updated Windows 7). So this mean you need to have Internet Explorer component in your Windows install.wim / install.esd.
If you want to remove Internet Explorer, you can still use this method!
Just protect these files 3 (6) files in components section in NTLite, you don't need to do it manually, just download and use attached preset RunOnceEx_Protector.xml

Lets start with preparing needed folder structure on your setup media

You also need Scripts folder inside sources\$OEM$\$$\Setup\Scripts - this folder is needed to call OOBE.cmd as this script is natively called by Windows Setup in all situations not like SetupComplete.cmd and OEM key "problem"
Save text bellow as OOBE.cmd into Scripts folder you created in previous step.
Code:
@echo off
TITLE Setting-up RunOnceEx
CLS
IF EXIST "%WINDIR%\SysWOW64" (
SET ARCH=x64
) ElSE (
SET ARCH=x86
)
SET FINTEXT="Windows Post-Setup"
SET CERTEXT="Installing certificates"
SET SCRIPTTEXT="Executing scripts"
SET OFFTEXT="Installing Microsoft Office"
SET MSITEXT="Installing MSI packages"
SET ACTTEXT="Activating products"
SET UPDTEXT="Installing updates"
SET SILTEXT="Installing applications"
SET TWKTEXT="Applying personal settings"
set DRVCLNTEXT="Removing unused drivers"
SET RBTTEXT="Reboot"
FOR %%I IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%I:\sources\install.esd SET DRIVE=%%I:
IF "%DRIVE%" == "" FOR %%I IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%I:\sources\install.wim SET DRIVE=%%I:
IF "%DRIVE%" == "" FOR %%I IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%I:\sources\install.swm SET DRIVE=%%I:
SET ROE=HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnceEx
IF EXIST "%WINDIR%\System32\iernonce.dll" (
REG ADD %ROE% /v Title /d %FINTEXT% /f
REG ADD %ROE% /v Flags /t REG_DWORD /d "00000024" /f
REM From Windows 8 up kill explorer.exe
IF NOT EXIST "%WINDIR%\Servicing\Version\6.1.*" (
REG ADD %ROE%\000 /ve /d " " /f
REG ADD %ROE%\000 /v "KillExplorer" /d "%WINDIR%\System32\cmd.exe /c \"start /min /wait %WINDIR%\setup\scripts\Watcher.cmd\"" /f
)
REM Install certificates into My / Root / CA store
IF EXIST "%DRIVE%\setup\*.cer" (
REG ADD %ROE%\001 /ve /d %CERTEXT% /f
FOR %%U IN ("%DRIVE%\setup\*.cer") DO (
REG ADD %ROE%\001 /v "%%~nU_TrustedPublisher" /d "%WINDIR%\System32\certutil.exe -addstore TrustedPublisher %%U" /f
REG ADD %ROE%\001 /v "%%~nU_My" /d "%WINDIR%\System32\certutil.exe -addstore My %%U" /f
REG ADD %ROE%\001 /v "%%~nU_CA" /d "%WINDIR%\System32\certutil.exe -addstore CA %%U" /f
REG ADD %ROE%\001 /v "%%~nU_Root" /d "%WINDIR%\System32\certutil.exe -addstore Root %%U" /f
)
)
REM Auto-install Microsoft Office 2008 - 2016
IF EXIST "%DRIVE%\office\%ARCH%\setup.exe" (
REG ADD %ROE%\002 /ve /d %OFFTEXT% /f
REG ADD %ROE%\002 /v "MSO" /d "%DRIVE%\office\%ARCH%\setup.exe" /f
) ELSE IF EXIST "%DRIVE%\office\All\setup.exe" (
REG ADD %ROE%\002 /ve /d %OFFTEXT% /f
REG ADD %ROE%\002 /v "MSO" /d "%DRIVE%\office\All\setup.exe" /f
)
REM Auto-install Microsoft Office 2019 / 365
IF EXIST "%DRIVE%\office\YAOCTRI_Installer.cmd" (
REG ADD %ROE%\002 /ve /d %OFFTEXT% /f
REG ADD %ROE%\002 /v "MSO" /d "%DRIVE%\office\YAOCTRI_Installer.cmd" /f
)
IF EXIST "%DRIVE%\office\YAOCTRIR_Installer.cmd" (
REG ADD %ROE%\002 /ve /d %OFFTEXT% /f
REG ADD %ROE%\002 /v "MSO" /d "%DRIVE%\office\YAOCTRIR_Installer.cmd" /f
)
REM Auto-install %ARCH% depend MSI packages
IF EXIST "%DRIVE%\setup\*-%ARCH%.msi" (
REG ADD %ROE%\003 /ve /d %MSITEXT% /f
FOR %%C IN ("%DRIVE%\setup\*-%ARCH%.msi") DO (
REM Get Installer
FOR /F "tokens=1 delims=-" %%G IN ("%%~nC") DO (
REM Get Switch
if exist "%DRIVE%\setup\%%G.txt" (
for /F "usebackq tokens=*" %%A in ("%DRIVE%\setup\%%G.txt") do (
REG ADD %ROE%\003 /v "%%~nC" /d "%%C %%A" /f
)
) else (
REG ADD %ROE%\003 /v "%%~nC" /d "msiexec /i %%C /quiet /norestart" /f
)
)
)
)
REM Auto-install %ARCH% independent MSI packages
IF EXIST "%DRIVE%\setup\*-all.msi" (
REG ADD %ROE%\003 /ve /d %MSITEXT% /f
FOR %%C IN ("%DRIVE%\setup\*-all.msi") DO (
REM Get Installer
FOR /F "tokens=1 delims=-" %%G IN ("%%~nC") DO (
REM Get Switch
if exist "%DRIVE%\setup\%%G.txt" (
for /F "usebackq tokens=*" %%A in ("%DRIVE%\setup\%%G.txt") do (
REG ADD %ROE%\003 /v "%%~nC" /d "%%C %%A" /f
)
) else (
REG ADD %ROE%\003 /v "%%~nC" /d "msiexec /i %%C /quiet /norestart" /f
)
)
)
)
REM Windows + Office activation
IF EXIST "%DRIVE%\support\Activate.cmd" (
REG ADD %ROE%\004 /ve /d %ACTTEXT% /f
REG ADD %ROE%\004 /v "Activation" /d "%WINDIR%\System32\cmd.exe /c \"start /min /wait %DRIVE%\support\Activate.cmd\"" /f
)
REM Install MSU / CAB / MSP Packages from %DRIVE%\updates
REG ADD %ROE%\005 /ve /d %UPDTEXT% /f
FOR %%U IN ("%DRIVE%\updates\*%ARCH%*.msu") DO REG ADD %ROE%\005 /v "%%~nU" /d "dism /Online /Add-Package /PackagePath:%%U /quiet /norestart" /f
FOR %%U IN ("%DRIVE%\updates\*%ARCH%*.cab") DO REG ADD %ROE%\005 /v "%%~nU" /d "dism /Online /Add-Package /PackagePath:%%U /quiet /norestart" /f
FOR %%U IN ("%DRIVE%\updates\*%ARCH%*.msp") DO REG ADD %ROE%\005 /v "%%~nU" /d "msiexec /i %%U /quiet /norestart" /f
REM Auto-install %ARCH% depend software with predefined silent switch
IF EXIST "%DRIVE%\setup\*-%ARCH%.exe" (
REG ADD %ROE%\006 /ve /d %SILTEXT% /f
FOR %%C IN ("%DRIVE%\setup\*-%ARCH%.exe") DO (
REM Get Installer
FOR /F "tokens=1 delims=-" %%G IN ("%%~nC") DO (
REM Get Switch
if exist "%DRIVE%\setup\%%G.txt" (
for /F "usebackq tokens=*" %%A in ("%DRIVE%\setup\%%G.txt") do (
REG ADD %ROE%\006 /v "%%~nC" /d "%%C %%A" /f
)
)
)
)
)
REM Auto-install %ARCH% independent software with predefined silent switch
IF EXIST "%DRIVE%\setup\*-all.exe" (
REG ADD %ROE%\006 /ve /d %SILTEXT% /f
FOR %%C IN ("%DRIVE%\setup\*-all.exe") DO (
REM Get Installer
FOR /F "tokens=1 delims=-" %%G IN ("%%~nC") DO (
REM Get Switch
if exist "%DRIVE%\setup\%%G.txt" (
for /F "usebackq tokens=*" %%A in ("%DRIVE%\setup\%%G.txt") do (
REG ADD %ROE%\006 /v "%%~nC" /d "%%C %%A" /f
)
)
)
)
)
REM Apply REG Tweaks from %DRIVE%\setup
IF EXIST "%DRIVE%\setup\*.reg" (
REG ADD %ROE%\007 /ve /d %TWKTEXT% /f
FOR %%U IN ("%DRIVE%\setup\*.reg") DO REG ADD %ROE%\007 /v "%%~nU" /d "regedit /s %%U" /f
)
REM Remove unused drivers from DriverStore
IF EXIST "%WINDIR%\setup\scripts\CleanDriverStore.cmd" (
REG ADD %ROE%\008 /ve /d %DRVCLNTEXT% /f
REG ADD %ROE%\008 /v "Driver CleanUp" /d "%WINDIR%\System32\cmd.exe /c \"start /min /wait %WINDIR%\setup\scripts\CleanDriverStore.cmd\"" /f
)
REM Custom PS1 / CMD / BAT scripts execution
REM PS1
FOR %%C IN ("%DRIVE%\setup\*.ps1") DO (
REG ADD %ROE%\009 /ve /d %SCRIPTTEXT% /f
REG ADD %ROE%\009 /v "%%C" /d "%WINDIR%\System32\cmd.exe /min /c \"start /wait powershell -NoLogo -WindowStyle Hidden -File \"%%C\"\"" /f
)
REM CMD
FOR %%C IN ("%DRIVE%\setup\*.cmd") DO (
REG ADD %ROE%\009 /ve /d %SCRIPTTEXT% /f
REG ADD %ROE%\009 /v "%%C" /d "%WINDIR%\System32\cmd.exe /min /c \"start /wait %%C\"" /f
)
REM BAT
FOR %%C IN ("%DRIVE%\setup\*.bat") DO (
REG ADD %ROE%\009 /ve /d %SCRIPTTEXT% /f
REG ADD %ROE%\009 /v "%%C" /d "%WINDIR%\System32\cmd.exe /min /c \"start /wait %%C\"" /f
)
REM Polish Start menu items and reboot
REG ADD %ROE%\010 /ve /d %RBTTEXT% /f
if exist "%WINDIR%\setup\scripts\StartMenu.cmd" (
REG ADD %ROE%\010 /v "01_StartMenu" /d "%WINDIR%\System32\cmd.exe /c \"start /min /wait %WINDIR%\setup\scripts\StartMenu.cmd\"" /f
)
REG ADD %ROE%\010 /v "02_Reboot" /d "%WINDIR%\System32\shutdown.exe -r -f -t 0" /f
REM Enable ROE
REG ADD %ROE% /d "%WINDIR%\System32\rundll32.exe %WINDIR%\System32\iernonce.dll,RunOnceExProcess" /f
)
exit
Continue in next post
Attachments
Last edited: