Raphire / Win11Debloat

A simple, easy to use PowerShell script to remove pre-installed apps from Windows, disable telemetry, remove Bing from Windows search as well as perform various other changes to declutter and improve your Windows experience. This script works for both Windows 10 and Windows 11.
MIT License
14.2k stars 615 forks source link

Some options do not work correctly in Sysprep mode #106

Closed Raphire closed 2 months ago

Raphire commented 3 months ago

Describe the bug Some options don't apply to any accounts if the script is run in Sysprep mode within the Windows Audit Mode environment.

To Reproduce Steps to reproduce the behavior:

  1. Start fresh installation of Windows 11
  2. Enter audit mode during OOBE (Ctrl + Shift + F3)
  3. Execute the script in Sysprep mode & select the options mentioned above
  4. Reboot
  5. Go through OOBE

Expected behavior The above mentioned options should apply to the account after going through OOBE

Raphire commented 3 months ago

After testing this I have been able to determine the script does apply the registry changes correctly to the default user profile. It seems however that these changes are not copied over to new users. I have been looking for alternative ways to apply these changes, but no luck so far.

sean-sauve commented 2 months ago

@Raphire, this might not fix your problem because you did say the change took effect properly, but you might try doing garbage collection first before closing the default registry hive. This is how I've done it in the past to ensure the hive takes effect properly. I had to do this during an Autopilot process or even though the registry got the change on the default hive the user that logged in wouldn't get the changed value.

        # $ITErrorCodes is a hashtable with keys with the friendly names of status codes and values for their errorcode number.  These lines can be omitted in your use case, this is just how my code worked.
        $unloaded = $false
        $attempts = 0
        $exitCode = $ITErrorCodes.Success
        while ((-not $unloaded) -and ($attempts -le 10)) {
            $attempts += 1
            Write-Host "Unloading the default user registry hive.  Attempt $attempts."
            [gc]::Collect()
            Start-Sleep -Seconds 5
            & reg.exe unload "$ITDefaultUserHiveLoad"
            $unloaded = $?
        }
        if (-not $unloaded) {
            Write-Warning "Unable to dismount default user registry hive at $ITDefaultUserHiveLoad.  Manual dismount required"
            Write-Warning "Setting exit code to $($ITErrorCodes.SuccessRebootRequired) SuccessRebootRequired"
            $exitCode = $ITErrorCodes.SuccessRebootRequired
        }
sean-sauve commented 2 months ago

Here's a better explanation. Apparently you're also supposed to close open handles before doing the garbage collection.

https://dansonnenburg.wordpress.com/2022/03/22/setting-value-in-the-default-user-registry-hive/

Raphire commented 2 months ago

@sean-sauve Thanks for the additional info and an example of your implementation. I am planning on reworking the way the script applies registry edits to also tackle #72.

LuCarhub commented 2 months ago

I think it's the same I read on the forum at the end of https://ccmexec.com/2021/10/modifying-windows-11-start-button-location-and-taskbar-icons-during-osd-autopilot/ and I reported on thread #104

Raphire commented 2 months ago

With 6b7c4db the following options now work in Sysprep mode:

Please note that these changes are applied to the user account after the OOBE, this means that they will have to sign-out and back in before the changes are visible.