Optimize-Offline Guide - Windows Debloating Tool, Windows 1803, 1903, 19H2, 1909, 20H1 and LTSC 2019

Discussion in 'Windows 10' started by KedarWolf, Jul 30, 2019.

  1. djsms

    djsms MDL Novice

    Feb 3, 2013
    18
    6
    0
    #1961 djsms, Sep 3, 2022
    Last edited: Sep 3, 2022
    Good tools. thanks...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. KedarWolf

    KedarWolf MDL Addicted

    Mar 17, 2016
    977
    874
    30
    @gdeliana

    From the main branch the commit the Snipping Tool tweak was added.

    Code:
    2022-09-04T02:19:19 [INFO]: Importing Registry Template: Additional Tweaks.reg
    2022-09-04T02:19:25 [INFO]: Applying Answer File.
    2022-09-04T02:19:29 [INFO]: Injecting Driver Packages into Windows 11 IoT Enterprise
    2022-09-04T02:21:45 [INFO]: Disabling automatic driver update
    2022-09-04T02:21:46 [INFO]: Enabling dormant OneDrive fix
    2022-09-04T02:21:47 [INFO]: Setting classic search explorer
    2022-09-04T02:21:49 [INFO]: Removing taskbar pinned icons
    2022-09-04T02:21:50 [INFO]: Setting W11 classic context menu
    2022-09-04T02:21:51 [INFO]: Disabling Microsoft Teams autostart entry
    2022-09-04T02:21:52 [INFO]: Disabling virtualization security
    2022-09-04T02:21:53 [INFO]: Enabling explorer classic UI ribbon
    2022-09-04T02:21:55 [INFO]: Adding AMOLED pitch-black theme
    2022-09-04T02:21:56 [INFO]: Importing Registry Template: AMOLED_black_theme.reg
    2022-09-04T02:22:00 [INFO]: Adding Powershell as trusted installer context menu entry
    2022-09-04T02:22:00 [INFO]: Importing Registry Template: RunAsTi.reg
    2022-09-04T02:22:06 [INFO]: Creating a Package Summary Log.
    2022-09-04T02:22:27 [INFO]: Post-Optimization Image Health State: [Healthy]
    2022-09-04T02:22:30 [INFO]: Saving and Dismounting Microsoft Windows Setup (x64)
    2022-09-04T02:22:50 [INFO]: Rebuilding and Exporting Microsoft Windows Setup (x64)
    2022-09-04T02:22:54 [INFO]: Saving and Dismounting Windows 11 IoT Enterprise
    2022-09-04T02:25:35 [INFO]: Rebuilding and Exporting Windows 11 IoT Enterprise using Maximum compression.
    2022-09-04T02:26:02 [INFO]: Optimizing the Installation Media File Structure.
    2022-09-04T02:26:02 [INFO]: Creating a No-Prompt Bootable Windows Installation Media ISO.
    2022-09-04T02:26:10 [INFO]: Finalizing Optimizations.
    2022-09-04T02:26:11 [INFO]: Optimize-Offline completed in [17] minutes with [0] errors.
    
    ***************************************************************************************************
    Optimizations Finalized : 09/04/2022 02:26:11 AM
    ***********************************************************************************
    From the latest main branch with the exact same answer file. The file manager is closed. The answer file is not open in a text editor or anything. Nothing is mounted except what the script mounts. A fresh reboot of Windows.

    Code:
    Index     : 0
    Exception : The process cannot access the file because it is being used by another process.
                
    Category  : NotSpecified: (:) [Add-WindowsDriver], COMException
    ErrorID   : Microsoft.Dism.Commands.AddWindowsDriverCommand
    Target    :
    Command   : [Void](Add-WindowsDriver @InstallDriverParams)
    Script    : D:\Optimize-Offline-master\Optimize-Offline-master\Optimize-Offline.psm1
    Line      : 2232
    Column    : 14
    
    Index     : 1
    Exception : The process cannot access the file because it is being used by another process.
                
    Category  : NotSpecified: (:) [Use-WindowsUnattend], COMException
    ErrorID   : Microsoft.Dism.Commands.UseWindowsUnattendCommand
    Target    :
    Command   : [Void](Use-WindowsUnattend @ApplyUnattendParams)
    Script    : D:\Optimize-Offline-master\Optimize-Offline-master\Optimize-Offline.psm1
    Line      : 2201
    Column    : 13
    
    Code:
    2022-09-04T02:56:01 [INFO]: Applying Answer File.
    2022-09-04T02:57:04 [ERROR]: Failed to Apply Answer File.
    2022-09-04T02:57:08 [INFO]: Injecting Driver Packages into Windows 11 IoT Enterprise
    2022-09-04T02:58:11 [ERROR]: Failed to Inject Driver Packages into Windows 11 IoT Enterprise
    2022-09-04T02:58:14 [INFO]: Disabling automatic driver update
    2022-09-04T02:58:15 [INFO]: Enabling dormant OneDrive fix
    2022-09-04T02:58:16 [INFO]: Setting classic search explorer
    2022-09-04T02:58:17 [INFO]: Removing taskbar pinned icons
    2022-09-04T02:58:19 [INFO]: Setting W11 classic context menu
    2022-09-04T02:58:20 [INFO]: Disabling Microsoft Teams autostart entry
    2022-09-04T02:58:21 [INFO]: Disabling virtualization security
    2022-09-04T02:58:22 [INFO]: Enabling explorer classic UI ribbon
    2022-09-04T02:58:24 [INFO]: Adding AMOLED pitch-black theme
    2022-09-04T02:58:24 [INFO]: Importing Registry Template: AMOLED_black_theme.reg
    2022-09-04T02:58:28 [INFO]: Adding Powershell as trusted installer context menu entry
    2022-09-04T02:58:29 [INFO]: Importing Registry Template: RunAsTi.reg
    2022-09-04T02:58:34 [INFO]: Creating a Package Summary Log.
    2022-09-04T02:58:37 [INFO]: Post-Optimization Image Health State: [Healthy]
    2022-09-04T02:58:40 [INFO]: Saving and Dismounting Microsoft Windows Setup (x64)
    2022-09-04T02:58:59 [INFO]: Rebuilding and Exporting Microsoft Windows Setup (x64)
    2022-09-04T02:59:03 [INFO]: Saving and Dismounting Windows 11 IoT Enterprise
    2022-09-04T03:00:43 [INFO]: Rebuilding and Exporting Windows 11 IoT Enterprise using Maximum compression.
    2022-09-04T03:00:57 [INFO]: Optimizing the Installation Media File Structure.
    2022-09-04T03:00:57 [INFO]: Creating a No-Prompt Bootable Windows Installation Media ISO.
    2022-09-04T03:01:01 [INFO]: Finalizing Optimizations.
    2022-09-04T03:01:01 [INFO]: Optimize-Offline completed in [15] minutes with [2] errors.
    
    ***************************************************************************************************
    Optimizations Finalized : 09/04/2022 03:01:01 AM
    ****************************************************************************
     
  3. zb9525

    zb9525 MDL Novice

    Apr 24, 2017
    38
    20
    0
  4. gdeliana

    gdeliana MDL Senior Member

    Oct 2, 2010
    365
    428
    10
    Sorry guys but i have no idea what is the answer file. Haven't used this part of the script yet.
    Can any of you supply a valid unattended file so that i can try myself and see what i can do.

    @KedarWolf The drivers issue may be because of the unattended error happening before if.

    @KedarWolf @zb9525 Just to let you know that these are Microsoft made powershell cmdlets, so the maximum i can do here is check the parameters supplied if they are correct or not.
     
  5. Rickkins

    Rickkins MDL Senior Member

    Jul 29, 2009
    439
    102
    10
    Hey hey, came here today looking for something exactly like this, for the old laptop...

    Thanks.
     
  6. gdeliana

    gdeliana MDL Senior Member

    Oct 2, 2010
    365
    428
    10
    Unattend.xml integration error solved, just removed the use of the special "Microsoft" cmdlet. @GodHand maybe will have a better fix for that. For me unattend configuration worked. Let me know if the same applies for you guys.

    Use latest master of course.

    Also am very interested into removing CloudExperienceHost, heard that can be done with unattend.xml configuration, but dunno the exact one for doing this. If anyone knows something more, please share it :)
     
  7. KedarWolf

    KedarWolf MDL Addicted

    Mar 17, 2016
    977
    874
    30
    Unattend integration works, but driver integration is messed up. Driver integration is fine on the Add Snipping Tool tweak commit.

    Code:
    Index     : 0
    Exception : The process cannot access the file because it is being used by another process.
               
    Category  : NotSpecified: (:) [Add-WindowsDriver], COMException
    ErrorID   : Microsoft.Dism.Commands.AddWindowsDriverCommand
    Target    :
    Command   : [Void](Add-WindowsDriver @InstallDriverParams)
    Script    : D:\Optimize-Offline-master\Optimize-Offline-master\Optimize-Offline.psm1
    Line      : 2233
    Column    : 14
    
     
  8. MajkelP

    MajkelP MDL Junior Member

    Nov 11, 2015
    59
    26
    0
    Hi, Any idea why MS Store doesn't work.
    I left theses windows apps in the image:

    Code:
        "Microsoft.VCLibs.*",
        "Microsoft.UI.Xaml.*",
        "Microsoft.StorePurchaseApp",
        "Microsoft.WindowsStore",
        "Microsoft.VCLibs.140.00",
        "Microsoft.VP9VideoExtensions",
        "Microsoft.WindowsTerminal
    "
    and SystemApps

    Code:
    [
                            "Microsoft.AAD.BrokerPlugin",
                            "Microsoft.AccountsControl",
                            "Microsoft.AsyncTextService",
                            "Microsoft.BioEnrollment",
                            "Microsoft.CredDialogHost",
                            "Microsoft.ECApp",
                            "Microsoft.LockApp",
                            "Microsoft.Win32WebViewHost",
                            "Microsoft.Windows.AddSuggestedFoldersToLibarayDialog",
                            "Microsoft.Windows.AppRep.ChxApp",
                            "Microsoft.Windows.AppResolverUX",
                            "Microsoft.Windows.AssignedAccessLockApp",
                            "Microsoft.Windows.CallingShellApp",
                            "Microsoft.Windows.CapturePicker",
                            "Microsoft.Windows.CloudExperienceHost",
                            "Microsoft.Windows.FilePicker",
                            "Microsoft.Windows.OOBENetworkCaptivePortal",
                            "Microsoft.Windows.OOBENetworkConnectionFlow",
                            "Microsoft.Windows.PinningConfirmationDialog",
                            "Microsoft.Windows.Search",
                            "Microsoft.Windows.SecHealthUI",
                            "Microsoft.Windows.ShellExperienceHost",
                            "Microsoft.Windows.StartMenuExperienceHost",
                            "MicrosoftWindows.Client.CBS",
                            "Windows.CBSPreview",
                            "windows.immersivecontrolpanel",
                            "Windows.PrintDialog"
     

    Attached Files:

  9. KedarWolf

    KedarWolf MDL Addicted

    Mar 17, 2016
    977
    874
    30
    For Windows Store I leave in:

    Code:
                "CortanaApp.View.App",
                            "Microsoft.DesktopAppInstaller",
                            "Microsoft.StorePurchaseApp",
                            "Microsoft.UI.Xaml.2.4",
                            "Microsoft.VCLibs.140.00",
                            "microsoft.windowscommunicationsapps",
                            "Microsoft.WindowsStore",
                            "Microsoft.WindowsTerminal",
                            "Microsoft.Xbox.TCUI",
                            "Microsoft.XboxGameOverlay",
                            "Microsoft.XboxGamingOverlay",
                            "Microsoft.XboxIdentityProvider",
                            "Microsoft.XboxSpeechToTextOverlay",
                            "MicrosoftWindows.Client.WebExperience"
    My full app list with everything I leave in is below:

    Code:
    {
        "DisplayName":  [
                            "CortanaApp.View.App",
                            "Microsoft.DesktopAppInstaller",
                            "Microsoft.GamingApp",
                            "Microsoft.HEIFImageExtension",
                            "Microsoft.Paint",
                            "Microsoft.PowerAutomateDesktop",
                            "Microsoft.ScreenSketch",
                            "Microsoft.StorePurchaseApp",
                            "Microsoft.UI.Xaml.2.4",
                            "Microsoft.VCLibs.140.00",
                            "Microsoft.VP9VideoExtensions",
                            "Microsoft.WebMediaExtensions",
                            "Microsoft.WebpImageExtension",
                            "microsoft.windowscommunicationsapps",
                            "Microsoft.WindowsStore",
                            "Microsoft.WindowsTerminal",
                            "Microsoft.Xbox.TCUI",
                            "Microsoft.XboxGameOverlay",
                            "Microsoft.XboxGamingOverlay",
                            "Microsoft.XboxIdentityProvider",
                            "Microsoft.XboxSpeechToTextOverlay",
                            "MicrosoftWindows.Client.WebExperience"
                        ]
     
  10. #1971 Deleted member 1531038, Sep 6, 2022
    Last edited by a moderator: Sep 6, 2022
    Must app for OOBE post process to complete.
    5 inbox apps are mandatory to be there inside as i have shown in my log for complete apps removal without those 5.

    Settings : immersive panel
    shell : shell experience host ( dependency of desktop experience)
    start menu : startmenu host ( dependency of desktop experience)
    cloud : oobe process
    undockeddevkit : oobe process

    Edit : But if we use autounattend ( complete auto unattended os installation with accounts creation then we can remove cloud as well as undock too ). that means its not good to go as most home users dont use autounattend & thery go process by process for setting up fresh installation. hence its a must to keep all theese 5 apps for oobe phase to complete flawlessly at user end without autounattend.

    now if we come to current installed online os

    no any inbox apps are needed except 3.
    immersive panel must app
    shell experience host must app
    start menu host ( user side decision as alternatives are there ie startallback etc etc)

    thats all nothing else needed for inbox apps in current installed scenario.
     
  11. gdeliana

    gdeliana MDL Senior Member

    Oct 2, 2010
    365
    428
    10
    Hello there, this is my whitelist for windows apps and for me store works :)
    I think DesktopAppInstaller is missing and needed.

    Code:
    "Microsoft.DesktopAppInstaller",
        "Microsoft.StorePurchaseApp",
        "Microsoft.VCLibs.140.00",
        "Microsoft.Xbox*",
        "Microsoft.UI.Xaml*",
        "Microsoft.WindowsTerminal",
        "Microsoft.WindowsStore"

     
  12. gdeliana

    gdeliana MDL Senior Member

    Oct 2, 2010
    365
    428
    10
    Can you send me the drivers you are trying to integrate?
     
  13. zb9525

    zb9525 MDL Novice

    Apr 24, 2017
    38
    20
    0
    Import-Registry.ps1
    Function Import-Registry
    {
    [CmdletBinding()]
    Param (
    [String]$Path,
    [Parameter(Mandatory=$false)]
    [switch]$RegistryLoaded = $false
    )

    $REGContentHandler = {
    param(
    [string]$Content
    )
    $Content = $Content -replace 'HKEY_CLASSES_ROOT', 'HKEY_LOCAL_MACHINE\WIM_HKLM_SOFTWARE\Classes'
    $Content = $Content -replace 'HKEY_LOCAL_MACHINE\\SOFTWARE', 'HKEY_LOCAL_MACHINE\WIM_HKLM_SOFTWARE'
    $Content = $Content -replace 'HKEY_LOCAL_MACHINE\\SYSTEM', 'HKEY_LOCAL_MACHINE\WIM_HKLM_SYSTEM'
    $Content = $Content -replace 'HKEY_CURRENT_USER', 'HKEY_LOCAL_MACHINE\WIM_HKCU'
    $Content = $Content -replace 'HKEY_USERS\\.DEFAULT', 'HKEY_LOCAL_MACHINE\WIM_HKU_DEFAULT'
    $Content = $Content -replace 'HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet', 'HKEY_LOCAL_MACHINE\WIM_HKLM_SYSTEM\ControlSet001'
    return $Content
    }

    If(!$RegistryLoaded) {
    RegHives -Load
    }


    If ((Get-Item $Path) -is [System.IO.DirectoryInfo]){
    Get-ChildItem -Path $Path -Filter *.Offline | Purge
    Get-ChildItem -Path $Path -Filter *.reg | ForEach-Object -Process {
    $REGContent = Get-Content -Path $PSItem.FullName -Raw
    $REGContent = $REGContentHandler.Invoke($REGContent)
    $REGContent | Set-Content -Path $PSItem.FullName.Replace($PSItem.Extension, '.Offline') -Encoding Unicode -Force
    }
    If (Get-ChildItem -Path $Path -Filter *.Offline)
    {
    Get-ChildItem -Path $Path -Filter *.Offline | ForEach-Object -Process {
    Try
    {
    Log ($OptimizeData.ImportingRegistryTemplate -f $PSItem.Name.Replace($PSItem.Extension, '.reg'))
    $RET = StartExe $REGEDIT -Arguments ('/S "{0}"' -f $PSItem.FullName)
    If ($RET -ne 0) { Throw }
    }
    Catch
    {
    Log ($OptimizeData.FailedImportingRegistryTemplate -f $PSItem.Name.Replace($PSItem.Extension, '.reg')) -Type Error
    }
    Finally
    {
    Purge $PSItem.FullName; Start-Sleep 2
    If(!$RegistryLoaded) {
    RegHives -Unload
    }
    }
    }
    }
    } Else {
    $RegFile = Get-Item $Path
    $REGContent = Get-Content -Path $RegFile.FullName -Raw
    $REGContent = $REGContentHandler.Invoke($REGContent)
    $REGContent | Set-Content -Path $RegFile.FullName.Replace($RegFile.Extension, '.Offline') -Encoding Unicode -Force

    $ProcessedItem = Get-Item $RegFile.FullName.Replace($RegFile.Extension, '.Offline')
    Try
    {
    Log ($OptimizeData.ImportingRegistryTemplate -f $ProcessedItem.Name.Replace($ProcessedItem.Extension, '.reg'))
    $RET = StartExe $REGEDIT -Arguments ('/S "{0}"' -f $ProcessedItem.FullName)
    If ($RET -ne 0) { Throw }
    }
    Catch
    {
    Log ($OptimizeData.FailedImportingRegistryTemplate -f $ProcessedItem.Name.Replace($ProcessedItem.Extension, '.reg')) -Type Error
    }
    Finally
    {
    Purge $ProcessedItem.FullName; Start-Sleep 2
    If(!$RegistryLoaded) {
    RegHives -Unload
    }
    }
    }

    If(!$RegistryLoaded) {
    RegHives -Unload
    }
    }
    code error Will cause
    RegHives -Unload
    unexecuted
    influence
    [Void](Use-WindowsUnattend @ApplyUnattendParams)
    [Void](Add-WindowsDriver @InstallDriverParams)
     
  14. KedarWolf

    KedarWolf MDL Addicted

    Mar 17, 2016
    977
    874
    30
    @gdeliana

    I'll test the new driver and unattend integration method when I get home from work in eight hours or so.

    I'm signed up for the notifications from GitHub. :)
     
  15. gdeliana

    gdeliana MDL Senior Member

    Oct 2, 2010
    365
    428
    10
    #1977 gdeliana, Sep 8, 2022
    Last edited: Sep 8, 2022
    Thanks i have applied the fix, now i see where was the error. My stupidity ;)
    Big thumbs up!! :)
     
  16. KedarWolf

    KedarWolf MDL Addicted

    Mar 17, 2016
    977
    874
    30
    I never use Component Cleanup because it has always given me an error message in the past.

    Will check with and without this evening.
     
  17. KedarWolf

    KedarWolf MDL Addicted

    Mar 17, 2016
    977
    874
    30
    @gdeliana Unattend and driver integration working.

    But I always get this error with "ComponentCleanup": true,

    Code:
    Cannot perform a clean-up of the Component Store while there are pending installations.
     
    remove component packages from offline image might be useful for OO as example i used Onedrive Package removal . User can remove as many packages he want defender too :

    Code:
    echo *****************************************************************
    echo --- Remove Component Packages From Offline Image
    echo *****************************************************************
    for %%z in (
    Microsoft-Windows-OneDrive-Setup-Package
    Microsoft-Windows-OneDrive-Setup-WOW64-Package
    ) do (
    echo.
    Powershell -C "Write-Host 'Removing: %%z'"
    echo.
    Reg load "HKLM\OfflineSOFTWARE" "mount\Windows\System32\config\SOFTWARE"
    Powershell -C "Set-ItemProperty -Path 'HKLM:OfflineSOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages\*%%z*' -Name Visibility -Value 1 -Force -EA 0 -Verbose"
    Powershell -C "Remove-Item -Path 'HKLM:OfflineSOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages\*%%z*' -Include *Owner* -Recurse -Force -EA 0 -Verbose"
    Reg unload "HKLM\OfflineSOFTWARE"
    Powershell -C "Get-WindowsPackage -Path 'mount' | Where {$_.PackageName -match '%%z' } | Remove-WindowsPackage -Path 'mount' -NoRestart -EA 0"
    )
    echo *****************************************************************