W4RH4WK / Debloat-Windows-10

A Collection of Scripts Which Disable / Remove Windows 10 Features and Apps
Other
6.09k stars 848 forks source link

Isn't "mkdir -Force" too destructive? #66

Closed ghost closed 8 years ago

ghost commented 8 years ago

I noticed your script is using the -Force flag on mkdir. I don't know Powershell enough but isn't that flag too destructive?

I was trying to add the new keys for ContentDeliveryManager and for some reason if I add that force flag it deletes all the subfolders of the target. I end it up using:

mkdir "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" -ErrorAction SilentlyContinue
sp "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" "FeatureManagementEnabled" 0
sp "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" "OemPreInstalledAppsEnabled" 0
sp "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" "PreInstalledAppsEnabled" 0
sp "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" "RotatingLockScreenEnabled" 0
sp "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" "RotatingLockScreenOverlayEnabled" 0
sp "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" "SilentInstalledAppsEnabled" 0
sp "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" "SoftLandingEnabled" 0
sp "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" "SubscribedContentEnabled" 0
sp "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" "SystemPaneSuggestionsEnabled" 0
sp "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" "PreInstalledAppsEverEnabled" 0
sp "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager" "ContentDeliveryAllowed" 0

Remove-Item -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager\SuggestedApps"

Am I wrong?

W4RH4WK commented 8 years ago

You are right, for some strange reason adding the -Force flag to mkdir will remove all subsequent registry keys. But this does not happen outside the registry.

ghost commented 8 years ago

Like I said I'm new to Powershell but I think this might work:

function createFullPath($path) {
    if (!(Test-Path $path)) {
        Write-Host "-- Creating full path to: " $path -ForegroundColor White -BackgroundColor DarkGreen
        New-Item -ItemType Directory -Force -Path $path
    }
}

createFullPath("HKCU:\SOFTWARE\Microsoft\Input\TIPC")

It's really dangerous to keep the force flag, I noticed the script removed some other folders that were present, for example, inside "HKCU:\SOFTWARE\Microsoft\Input\TIPC".

By the way feel free to use the code I mentioned before, I think it's something MS implemented on the AU. I was getting suggested apps installed even on Enterprise. That's the only way I was able to stop it.

Anyway, thanks for the awesome script!

Another suggestion: maybe we could do some kind of executable test suite that shows if any of the configs changed on an update. Maybe a startup script that only shows output if any test failed.

Proof of concept:

function runTest() {
    param ($name, $value, $expected)

    Write-Host 'Test:' $name

    if ($value -eq $expected) {
        Write-Host 'SUCCESS' -ForegroundColor White -BackgroundColor DarkGreen
    } else {
        Write-Host 'FAIL' -ForegroundColor White -BackgroundColor Red
        Write-Host 'Value:' $value -ForegroundColor White -BackgroundColor Red
        Write-Host 'Expected:' $expected -ForegroundColor White -BackgroundColor Red
    }
}

# run tests
$v = (Get-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\datacollection).allowtelemetry
runTest -name 'Allow telemetry' -value $v -expected 0