TUTORIAL: Create perfect Windows Post-Setup using OOBE.cmd

George King

Active Member

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

RunOnceEx_Protector.PNG

Lets start with preparing needed folder structure on your setup media

1600513692006.png

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

  • RunOnceEx_Protector.xml
    1.8 KB
Last edited:
If you are on Windows 8+ you also need to Watcher.cmd (place them in same folder as OOBE.cmd) to kill explorer.exe process for better user experience
Code:
@echo off
title Windows Explorer Watcher
cls

set ProcessToFind=explorer.exe

:PerformCheck
for /f "tokens=1 delims= " %%G in ('tasklist ^| findstr %ProcessToFind%') do set RunningProcess=%%G

if "%RunningProcess%" == "%ProcessToFind%" (
    taskkill /im %ProcessToFind% /f
    exit
) else (
    timeout 5 >nul
    goto :PerformCheck
)

Now you are almost done to add Microsoft Office, Applications installers and your registry keys (You can also integrate registry keys directly into you image using NTLite registry page, but if you are installing for example WinRar and you want to configure application settings you need to do it using this method)

Add your unattented Office installer, tutorial for 2007 / 2010 / 2013 / 2016 can be found here, for Office 2019 / 365 use YAOCTRI. So next step is to simply copy installation files into Office folder you created before. But you need to remember some things around it.

If you are using Office 2007, place them into All folder as this Office suite is only 32bit (x86)

For Office 2010 / 2013 / 2016, place your 32bit setup into x86 folder, 64bit setup into x64
1600517484471.png

For Office 2019 / 365 place all needed files created by YAOCTRI directly into Office folder
1602663650516.png
For fully silent installation you need to modify YAOCTRI_Installer.cmd / YAOCTRIR_Installer.cmd using notepad :TheEnd section to looks like this, so script ends after installing and Post-Setup can continue as usual
Code:
:TheEnd
rem echo.
rem echo Press any key to exit.
rem pause >nul
rem goto :eof
exit

There is one more line that needs to be modified if you want use both x86 and x64 Office. Search for this line
Code:
if exist "!_work!\C2R_*.ini" for /f "tokens=* delims=" %%# in ('dir /b "!_work!\C2R_*.ini"') do set "C2Rconfig=!_work!\%%#"
And replace it with those 2 lines, this means config file will be loaded with right architecture, so x64 on 64bit system, x86 on 32bit system.
Code:
if exist "%windir%\SysWOW64" (set arch=x64) else (set arch=x86)
if exist "!_work!\C2R*_*%arch%.ini" for /f "tokens=* delims=" %%# in ('dir /b "!_work!\C2R*_*%arch%.ini"') do set "C2Rconfig=!_work!\%%#"


If you have needed Windows updates and you don't have time to re-create your install.wim / install.esd using NTLite, simply place them inside Updates folder you created before. Don't forget to keep x64 / x86 in file name so script (OOBE.cmd) can detect correct version to install as architecture is detected from installed Windows - this means if you are using 32bit Windows on 64bit CPU - for some reason, like 4GB RAM only, so everything is correctly installed.
1600517497020.png

This was really easy right? :)

Now is time to add your applications installers inside Setup folder. If you want add MSI installer it's easy, just place them inside and it will be silently installed (automatically using /quiet /norestart parameters). If you want specify your own switch it's also easy and same way as specifying silent switch for EXE installers described bellow.


If there are 32bit and 64bit installer for your application, keep -x64 or -x86 in file name. If it's architecture independent keep -all in file name.
For better explain how it works. OOBE.cmd search for *.exe or *.msi file in %DVD%\setup ( DVD / USB drive is detected by searching for \sources\install.esd or wim or swm when OOBE.cmd is launched). And after that is installer file name splited by - (dash) delimiter to open correct TXT file with switch for both architecture.

So this is how looks my setup folder.

Specify your switch as only single line into TXT file. For example in .NET5.txt is silent setup switch /install /quiet /norestart

1600517568784.png


You can add / delete applications installers without need to modify script. This folder is dynamically readed so you should love this solution :)

If you place .REG file inside setup folder and it will be automatically applied.

If you want to cleanup Start Menu items OOBE.cmd looks for StartMenu.cmd in same folder. This is example of script which performs moving or deleting Start Menu items in my Windows 7 installation
Code:
@echo off
TITLE StartMenu CleanUp
cls



move /y "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Embedded Lockdown Manager\Embedded Lockdown Manager.lnk" "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\System Tools\Embedded Lockdown Manager.lnk"
if exist "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Embedded Lockdown Manager" rd /q /s "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Embedded Lockdown Manager"


move /y "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Windows Server Essentials\ClientDeployPrograms.lnk" "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\ClientDeployPrograms.lnk"
if exist "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Windows Server Essentials" rd /q /s "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Windows Server Essentials"


if exist "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Silverlight" rd /q /s "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Silverlight"


move /y "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Windows Virtual PC" "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Windows Virtual PC"


move /y "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Windows Fax and Scan.lnk" "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Windows Fax and Scan.lnk"
move /y "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\XPS Viewer.lnk" "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\XPS Viewer.lnk"


move /y "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\System Tools" "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\System Tools"
move /y "%SYSTEMDRIVE%\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\System Tools" "%SYSTEMDRIVE%\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\System Tools"


del /q /s "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Sidebar.lnk"


move /y "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Default Programs.lnk" "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\System Tools\Default Programs.lnk"


REM Custom 3rd apps
if exist "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\wufuc" rd /q /s "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\wufuc"
if exist "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Command Line Clipboard" rd /q /s "%SYSTEMDRIVE%\ProgramData\Microsoft\Windows\Start Menu\Programs\Command Line Clipboard"

exit


If you have integrated bunch of drivers to have universal setup media for more hardware and you want remove unused drivers to save space in your DriverStore use this script as CleanDriverStore.cmd, place them also in folder with OOBE.cmd
Code:
@echo off
title Windows DriverStore CleanUp
cls

echo.
echo Creating Restore Point

"%WinDir%\System32\wbem\wmic.exe" /Namespace:\\root\default Path SystemRestore Call CreateRestorePoint "DriverStore CleanUp %DATE%", 100, 1 >nul

REM Get count of all OEM drivers
set OEMDRVCNT=0
for %%A in ("%WinDir%\inf\OEM*.inf") do set /a OEMDRVCNT+=1

echo.

REM Remove unused 3rd drivers, drivers in use will be skipped with error
for /L %%A in (0,1,%OEMDRVCNT%) do (
    if exist "%WinDir%\inf\OEM%%A.inf" (
        echo Deleting "%WinDir%\inf\OEM%%A.inf"
        "%WinDir%\system32\pnputil.exe" -d "OEM%%A.inf"
    )
)

exit

Continue in next post
 
Last edited:
If you want automatically activate Windows and Office, create Activate.cmd inside support folder and follow Windows and Office Microsoft documents.

If you are going to install your own Windows product key specified in Activate.cmd just add these commands at the end of OOBE.cmd before exit command.
So you avoid problem with Windows to use OEM key automatically readed from BIOS, discussed here.
Code:
REM Remove generic installation product key

REM Uninstall the current product key from Windows and put it into an unlicensed state
"%WinDir%\System32\cscript.exe" /Nologo "%WinDir%\System32\slmgr.vbs" /upk

REM Remove the product key from the registry if it's still there
"%WinDir%\System32\cscript.exe" /Nologo "%WinDir%\System32\slmgr.vbs" /cpky

REM Reset Windows Activation
"%WinDir%\System32\cscript.exe" /Nologo "%WinDir%\System32\slmgr.vbs" /rearm

Removing product key is also usefull if you have integrated product key inside install.esd (wim / swm) for some reason, more info here.


You can include PS1 / CMD / BAT scripts inside setup folder, they will be automatically executed. Just remember to have exit command inside to keep it unattented.

Also if you need add automatically certificates, place any .CER files into setup folder and they will be added into TrustedPublisher / My / Root and CA store using certutil.


After you completed these steps create ISO and perform installation. After OOBE phase is finished (User is created and you specified some settings) you should see this screen

1605209070186.png


Hope you enjoy



Changelog

07.01.2020
  • Fixed typo in MSI installing without parameters, thanks to empty

15.12.2020
  • Added certificates installing into TrustedPublisher

12.11.2020
  • Added certificates installing into My, Root, CA store
  • Added custom scripts execution support, PS1, CMD and BAT
  • Added missing depencies for images with Internet Explorer 9 up
  • Attached RunOnceEx_Protector.xml for easier Internet Explorer removal with working RunOnceEx
16.10.2020
  • Added missing information for multi architecture Office 2019 / 365 installer
14.10.2020
  • Added support for installing Office 2019 / 365
20.09.2020
  • Redesigned and added forgotten information about Activate.cmd
 
Last edited:
Thanks, it is definitely a usefull way to do these jobs. Will use some of them in the future!

Just an idea; do you think you can add support for subdirectories for setup folder? So people can group into folders...

BTW why do you remove windows key? and will u share activate.cmd? It looks like kms_vl_all? or did u integrate hwidgen too
 
Last edited:
Im going to test idea with subfolders. Seems interesting.

Removing product key is usefull only in some scenarios.
Like image with preintegrated key by DISM
Code:
dism /image:"%image%" /Set-ProductKey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

Or if setup automaticaly install different key from BIOS, discussed here.

For Activate.cmd inside support folder, I forget to mention. Use what you want, I designed it for original Microsoft way for Windows or Office
 
George King Awesome tutorial. One question, like ege914 was saying, is it possible to add subdirectories for the setup folder under $OEM$ - see the snip below just to get general idea:
View attachment 3955

As i see you are still placing software folder under C drive :) if u use my script then it should look like this, 1600588275056.png under main directory of iso

Im going to test idea with subfolders. Seems interesting.

Removing product key is usefull only in some scenarios.
Like image with preintegrated key by DISM
Code:
dism /image:"%image%" /Set-ProductKey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

Or if setup automaticaly install different key from BIOS, discussed here.

For Activate.cmd inside support folder, I forget to mention. Use what you want, I designed it for original Microsoft way for Windows or Office

Also maybe you can add support for updates folder too.. subfolders as W7 W8 W8.1 W10? so AIO iso's can process correct updates according to installed environment?
 
Last edited:
Also maybe you can add support for updates folder too.. subfolders as W7 W8 W8.1 W10? so AIO iso's can process correct updates according to installed environment?

I don't think its needed, as updates for different operting system going to fail.. But it can be done by reading filename 6.1 - Windows 7 etc.. But also seems interesting, I will test it to have clear way instead of trying installing W10 update on W7

ege914 write me PM, I want to discuss about more ideas :)
 
As i see you are still placing software folder under C drive :) if u use my script then it should look like this, View attachment 3957 under main directory of iso



Also maybe you can add support for updates folder too.. subfolders as W7 W8 W8.1 W10? so AIO iso's can process correct updates according to installed environment?

ege914 I get what you were saying - I basically was doing some experimental to see what work and what not:cool:
 
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

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. 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 2 (4) files in components section in NTLite, don't forget to replace cs-CZ with your language code

View attachment 3940

Lets start with preparing needed folder structure on your setup media

View attachment 3941

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 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 DRVCLNTXT="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 "00000014" /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 Auto-install Microsoft Office
    IF EXIST "%DRIVE%\office\%ARCH%\setup.exe" (
        REG ADD %ROE%\001 /ve /d %OFFTEXT% /f
        REG ADD %ROE%\001 /v "MSO" /d "%DRIVE%\office\%ARCH%\setup.exe" /f
    ) ELSE IF EXIST "%DRIVE%\office\All\setup.exe" (
        REG ADD %ROE%\001 /ve /d %OFFTEXT% /f
        REG ADD %ROE%\001 /v "MSO" /d "%DRIVE%\office\All\setup.exe" /f
    )


    REM Auto-install %ARCH% depend MSI packages
    IF EXIST "%DRIVE%\setup\*-%ARCH%.msi" (
        REG ADD %ROE%\002 /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%\002 /v "%%~nC" /d "%%C %%A" /f
                    )
                ) else (
                    REG ADD %ROE%\002 /v "%%~nU" /d "msiexec /i %%U /quiet /norestart" /f
                )
            )
        )
    )


    REM Auto-install %ARCH% independent MSI packages
    IF EXIST "%DRIVE%\setup\*-all.msi" (
        REG ADD %ROE%\002 /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%\002 /v "%%~nC" /d "%%C %%A" /f
                    )
                ) else (
                    REG ADD %ROE%\002 /v "%%~nU" /d "msiexec /i %%U /quiet /norestart" /f
                )
            )
        )
    )


    REM Windows + Office activation
    IF EXIST "%DRIVE%\support" (
        REG ADD %ROE%\003 /ve /d %ACTTEXT% /f
        REG ADD %ROE%\003 /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%\004 /ve /d %UPDTEXT% /f
    FOR %%U IN ("%DRIVE%\updates\*%ARCH%*.msu") DO REG ADD %ROE%\004 /v "%%~nU" /d "dism /Online /Add-Package /PackagePath:%%U /quiet /norestart" /f
    FOR %%U IN ("%DRIVE%\updates\*%ARCH%*.cab") DO REG ADD %ROE%\004 /v "%%~nU" /d "dism /Online /Add-Package /PackagePath:%%U /quiet /norestart" /f
    FOR %%U IN ("%DRIVE%\updates\*%ARCH%*.msp") DO REG ADD %ROE%\004 /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%\005 /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%\005 /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%\005 /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%\005 /v "%%~nC" /d "%%C %%A" /f
                    )
                )
            )
        )
    )


    REM Apply REG Tweaks from %DRIVE%\setup
    IF EXIST "%DRIVE%\setup\*.reg" (
        REG ADD %ROE%\006 /ve /d %TWKTEXT% /f
        FOR %%U IN ("%DRIVE%\setup\*.reg") DO REG ADD %ROE%\006 /v "%%~nU" /d "regedit /s %%U" /f
    )


    REM Remove unused drivers from DriverStore
    IF EXIST "%WINDIR%\setup\scripts\CleanDriverStore.cmd" (
        REG ADD %ROE%\007 /ve /d %DRVCLNTXT% /f
        REG ADD %ROE%\007 /v "Driver CleanUp" /d "%WINDIR%\System32\cmd.exe /c \"start /min /wait %WINDIR%\setup\scripts\CleanDriverStore.cmd\"" /f
    )


    REM Polish Start menu items and reboot
    REG ADD %ROE%\008 /ve /d %RBTTEXT% /f
    if exist "%WINDIR%\setup\scripts\StartMenu.cmd" (
        REG ADD %ROE%\008 /v "01_StartMenu" /d "%WINDIR%\System32\cmd.exe /c \"start /min /wait %WINDIR%\setup\scripts\StartMenu.cmd\"" /f
    )
    REG ADD %ROE%\008 /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

)


REM Remove generic installation product key

REM Uninstall the current product key from Windows and put it into an unlicensed state
REM "%WinDir%\System32\cscript.exe" /Nologo "%WinDir%\System32\slmgr.vbs" /upk

REM Remove the product key from the registry if it's still there
REM "%WinDir%\System32\cscript.exe" /Nologo "%WinDir%\System32\slmgr.vbs" /cpky

REM Reset Windows Activation
REM "%WinDir%\System32\cscript.exe" /Nologo "%WinDir%\System32\slmgr.vbs" /rearm

exit


Continue in next post
Hi, this is a really great tutorial however i'm new to NTLite do you have a step by step tutorial which I can follow a long?
and is it possible to add a custom flexible like this https://gregramsey.net/?s=script+to+import+custom+drivers in NTLite? I think it might be more useful to just use driver you need instead of adding all driver into image.

thanks in advance
 
Back
Top