@@ -5,6 +5,9 @@ function Invoke-WPFUpdatesdefault {
55 Resets Windows Update settings to default
66
77 #>
8+
9+ Write-Host " Restoring Windows Update registry settings..." - ForegroundColor Yellow
10+
811 If (! (Test-Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" )) {
912 New-Item - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" - Force | Out-Null
1013 }
@@ -15,17 +18,99 @@ function Invoke-WPFUpdatesdefault {
1518 }
1619 Set-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config" - Name " DODownloadMode" - Type DWord - Value 1
1720
21+ # Reset WaaSMedicSvc registry settings to defaults
22+ Write-Host " Restoring WaaSMedicSvc settings..." - ForegroundColor Yellow
23+ Set-ItemProperty - Path " HKLM:\SYSTEM\CurrentControlSet\Services\WaaSMedicSvc" - Name " Start" - Type DWord - Value 3 - ErrorAction SilentlyContinue
24+ Remove-ItemProperty - Path " HKLM:\SYSTEM\CurrentControlSet\Services\WaaSMedicSvc" - Name " FailureActions" - ErrorAction SilentlyContinue
25+
26+ # Restore update services to their default state
27+ Write-Host " Restoring update services..." - ForegroundColor Yellow
28+
1829 $services = @ (
19- " BITS"
20- " wuauserv"
30+ @ {Name = " BITS" ; StartupType = " Manual" },
31+ @ {Name = " wuauserv" ; StartupType = " Manual" },
32+ @ {Name = " UsoSvc" ; StartupType = " Automatic" },
33+ @ {Name = " uhssvc" ; StartupType = " Disabled" },
34+ @ {Name = " WaaSMedicSvc" ; StartupType = " Manual" }
2135 )
2236
2337 foreach ($service in $services ) {
24- # -ErrorAction SilentlyContinue is so it doesn't write an error to stdout if a service doesn't exist
38+ try {
39+ Write-Host " Restoring $ ( $service.Name ) to $ ( $service.StartupType ) ..."
40+ $serviceObj = Get-Service - Name $service.Name - ErrorAction SilentlyContinue
41+ if ($serviceObj ) {
42+ Set-Service - Name $service.Name - StartupType $service.StartupType - ErrorAction SilentlyContinue
43+
44+ # Reset failure actions to default using sc command
45+ Start-Process - FilePath " sc.exe" - ArgumentList " failure `" $ ( $service.Name ) `" reset= 86400 actions= restart/60000/restart/60000/restart/60000" - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
46+
47+ # Start the service if it should be running
48+ if ($service.StartupType -eq " Automatic" ) {
49+ Start-Service - Name $service.Name - ErrorAction SilentlyContinue
50+ }
51+ }
52+ }
53+ catch {
54+ Write-Host " Warning: Could not restore service $ ( $service.Name ) - $ ( $_.Exception.Message ) " - ForegroundColor Yellow
55+ }
56+ }
2557
26- Write-Host " Setting $service StartupType to Automatic"
27- Get-Service - Name $service - ErrorAction SilentlyContinue | Set-Service - StartupType Automatic
58+ # Restore renamed DLLs if they exist
59+ Write-Host " Restoring renamed update service DLLs..." - ForegroundColor Yellow
60+
61+ $dlls = @ (" WaaSMedicSvc" , " wuaueng" )
62+
63+ foreach ($dll in $dlls ) {
64+ $dllPath = " C:\Windows\System32\$dll .dll"
65+ $backupPath = " C:\Windows\System32\${dll} _BAK.dll"
66+
67+ if ((Test-Path $backupPath ) -and ! (Test-Path $dllPath )) {
68+ try {
69+ # Take ownership of backup file
70+ Start-Process - FilePath " takeown.exe" - ArgumentList " /f `" $backupPath `" " - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
71+
72+ # Grant full control to everyone
73+ Start-Process - FilePath " icacls.exe" - ArgumentList " `" $backupPath `" /grant *S-1-1-0:F" - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
74+
75+ # Rename back to original
76+ Rename-Item - Path $backupPath - NewName " $dll .dll" - ErrorAction SilentlyContinue
77+ Write-Host " Restored ${dll} _BAK.dll to $dll .dll"
78+
79+ # Restore ownership to TrustedInstaller
80+ Start-Process - FilePath " icacls.exe" - ArgumentList " `" $dllPath `" /setowner `" NT SERVICE\TrustedInstaller`" " - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
81+ Start-Process - FilePath " icacls.exe" - ArgumentList " `" $dllPath `" /remove *S-1-1-0" - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
82+ }
83+ catch {
84+ Write-Host " Warning: Could not restore $dll .dll - $ ( $_.Exception.Message ) " - ForegroundColor Yellow
85+ }
86+ }
2887 }
88+
89+ # Enable update related scheduled tasks
90+ Write-Host " Enabling update related scheduled tasks..." - ForegroundColor Yellow
91+
92+ $taskPaths = @ (
93+ ' \Microsoft\Windows\InstallService\*'
94+ ' \Microsoft\Windows\UpdateOrchestrator\*'
95+ ' \Microsoft\Windows\UpdateAssistant\*'
96+ ' \Microsoft\Windows\WaaSMedic\*'
97+ ' \Microsoft\Windows\WindowsUpdate\*'
98+ ' \Microsoft\WindowsUpdate\*'
99+ )
100+
101+ foreach ($taskPath in $taskPaths ) {
102+ try {
103+ $tasks = Get-ScheduledTask - TaskPath $taskPath - ErrorAction SilentlyContinue
104+ foreach ($task in $tasks ) {
105+ Enable-ScheduledTask - TaskName $task.TaskName - TaskPath $task.TaskPath - ErrorAction SilentlyContinue
106+ Write-Host " Enabled task: $ ( $task.TaskName ) "
107+ }
108+ }
109+ catch {
110+ Write-Host " Warning: Could not enable tasks in path $taskPath - $ ( $_.Exception.Message ) " - ForegroundColor Yellow
111+ }
112+ }
113+
29114 Write-Host " Enabling driver offering through Windows Update..."
30115 Remove-ItemProperty - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\Device Metadata" - Name " PreventDeviceMetadataFromNetwork" - ErrorAction SilentlyContinue
31116 Remove-ItemProperty - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\DriverSearching" - Name " DontPromptForWindowsUpdate" - ErrorAction SilentlyContinue
@@ -39,6 +124,7 @@ function Invoke-WPFUpdatesdefault {
39124 Remove-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" - Name " BranchReadinessLevel" - ErrorAction SilentlyContinue
40125 Remove-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" - Name " DeferFeatureUpdatesPeriodInDays" - ErrorAction SilentlyContinue
41126 Remove-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" - Name " DeferQualityUpdatesPeriodInDays" - ErrorAction SilentlyContinue
127+
42128 Write-Host " ==================================================="
43129 Write-Host " --- Windows Update Settings Reset to Default ---"
44130 Write-Host " ==================================================="
@@ -62,4 +148,6 @@ function Invoke-WPFUpdatesdefault {
62148 Write-Host " ==================================================="
63149 Write-Host " --- Windows Local Policies Reset to Default ---"
64150 Write-Host " ==================================================="
151+
152+ Write-Host " Note: A system restart may be required for all changes to take full effect." - ForegroundColor Yellow
65153}
0 commit comments