Disassembler0 / Win10-Initial-Setup-Script

PowerShell script for automation of routine tasks done after fresh installations of Windows 10 / Server 2016 / Server 2019
MIT License
4.7k stars 1.08k forks source link

Receive updates for other Microsoft products? #250

Closed abrookewood closed 5 years ago

abrookewood commented 5 years ago

Hi, just wondering if there is a tweak for controlling whether or not the machine will "Receive updates for other Microsoft products when you update Windows"? This setting is visible under: Settings > Windows Update > Advanced Options.

Excellent tool by the way - has saved me hours of pain!

Disassembler0 commented 5 years ago

Try this

If (!(Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending\7971f918-a847-4430-9279-4a52d1efe18d")) {
    New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending\7971f918-a847-4430-9279-4a52d1efe18d" -Force | Out-Null
}
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending\7971f918-a847-4430-9279-4a52d1efe18d" -Name "RegisterWithAU" -Type DWord -Value 1

I haven't tested it extensively, though.

There is also GPO setting AllowMUUpdateService value under HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU, but it seems that the registry modification alone isn't enough. Moreover this GPO is bundled with other updates settings and affects more than just the downloads for other MS products, so the snippet above is probably a safer bet. I'll consider adding it after I do some more tests.

abrookewood commented 5 years ago

I tried both the keys you provided as well as the GPO setting, but couldn't generate any changes.

Out of interest, I used ProcMon to watch the registry while I changed the settings manually in the GUI and I did notice that the keys in your suggestion are only used temporarily. If you look at the screenshot, you can see that they are subsequently copied and the original key (with the "Pending" in the path) is deleted.

I modified your code to exclude the Pending from the path, but didn't have any success with that either. 2019-06-19 13_54_42-Process Monitor - Sysinternals_ www sysinternals com

abrookewood commented 5 years ago

I reverted to your original suggestion and I can see that it registry change stays in the Pending state even after logging in/out. I'm not sure what the trigger is, but when I watch the registry, it never seems to copy the key to the other location.

I also tried to imitate all the changes that I see in the registry with the following code, but it doesn't seem to work. I can't see any registry differences between what I end up with when I run this and what I get when I make the change via the GUI, but it doesn't work. Maybe there's config stored outside the registry?

If (!(Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending\7971f918-a847-4430-9279-4a52d1efe18d")) {
    New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending\7971f918-a847-4430-9279-4a52d1efe18d" -Force | Out-Null
}
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending\7971f918-a847-4430-9279-4a52d1efe18d" -Name "ClientApplicationID" -Type String -Value "UpdateOrchestrator"
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending\7971f918-a847-4430-9279-4a52d1efe18d" -Name "RegisterWithAU" -Type DWord -Value 1

If (!(Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services")) {
    New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services" -Force | Out-Null
}
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services" -Name "DefaultService" -Type String -Value "7971f918-a847-4430-9279-4a52d1efe18d"

If (!(Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\7971F918-A847-4430-9279-4A52D1EFE18D")) {
    New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\7971F918-A847-4430-9279-4A52D1EFE18D" -Force | Out-Null
}
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\7971F918-A847-4430-9279-4A52D1EFE18D" -Name "RegisteredWithAU" -Type DWord -Value 1

Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending\7971F918-A847-4430-9279-4A52D1EFE18D" -Force | Out-Null
farag2 commented 5 years ago

@abrookewood https://github.com/farag2/Setup-Windows-10/blob/master/Win%2010.ps1#L496

abrookewood commented 5 years ago

For anyone looking for the solution, @farag2 has provided the following, which works perfectly:

(New-Object -ComObject Microsoft.Update.ServiceManager).AddService2("7971f918-a847-4430-9279-4a52d1efe18d", 7, "")