@@ -6,30 +6,130 @@ function Invoke-WPFUpdatesdisable {
66
77 . NOTES
88 Disabling Windows Update is not recommended. This is only for advanced users who know what they are doing.
9+ This function requires administrator privileges and will attempt to run as SYSTEM for certain operations.
910
1011 #>
12+
13+ Write-Host " Configuring registry settings..." - ForegroundColor Yellow
14+
1115 If (! (Test-Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" )) {
1216 New-Item - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" - Force | Out-Null
1317 }
1418 Set-ItemProperty - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" - Name " NoAutoUpdate" - Type DWord - Value 1
1519 Set-ItemProperty - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" - Name " AUOptions" - Type DWord - Value 1
20+
1621 If (! (Test-Path " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config" )) {
1722 New-Item - Path " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config" - Force | Out-Null
1823 }
1924 Set-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config" - Name " DODownloadMode" - Type DWord - Value 0
25+
26+ # Additional registry settings
27+ Set-ItemProperty - Path " HKLM:\SYSTEM\CurrentControlSet\Services\WaaSMedicSvc" - Name " Start" - Type DWord - Value 4 - ErrorAction SilentlyContinue
28+ $failureActions = [byte []](0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x03 , 0x00 , 0x00 , 0x00 , 0x14 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xc0 , 0xd4 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xe0 , 0x93 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 )
29+ Set-ItemProperty - Path " HKLM:\SYSTEM\CurrentControlSet\Services\WaaSMedicSvc" - Name " FailureActions" - Type Binary - Value $failureActions - ErrorAction SilentlyContinue
2030
31+ # Disable and stop update related services
32+ Write-Host " Disabling update services..." - ForegroundColor Yellow
33+
2134 $services = @ (
2235 " BITS"
2336 " wuauserv"
37+ " UsoSvc"
38+ " uhssvc"
39+ " WaaSMedicSvc"
2440 )
2541
2642 foreach ($service in $services ) {
27- # -ErrorAction SilentlyContinue is so it doesn't write an error to stdout if a service doesn't exist
43+ try {
44+ Write-Host " Stopping and disabling $service ..."
45+ $serviceObj = Get-Service - Name $service - ErrorAction SilentlyContinue
46+ if ($serviceObj ) {
47+ Stop-Service - Name $service - Force - ErrorAction SilentlyContinue
48+ Set-Service - Name $service - StartupType Disabled - ErrorAction SilentlyContinue
49+
50+ # Set failure actions to nothing using sc command
51+ Start-Process - FilePath " sc.exe" - ArgumentList " failure `" $service `" reset= 0 actions= `"`" " - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
52+ }
53+ }
54+ catch {
55+ Write-Host " Warning: Could not process service $service - $ ( $_.Exception.Message ) " - ForegroundColor Yellow
56+ }
57+ }
58+
59+ # Rename critical update service DLLs (requires SYSTEM privileges)
60+ Write-Host " Attempting to rename critical update service DLLs..." - ForegroundColor Yellow
61+
62+ $dlls = @ (" WaaSMedicSvc" , " wuaueng" )
63+
64+ foreach ($dll in $dlls ) {
65+ $dllPath = " C:\Windows\System32\$dll .dll"
66+ $backupPath = " C:\Windows\System32\${dll} _BAK.dll"
67+
68+ if (Test-Path $dllPath ) {
69+ try {
70+ # Take ownership
71+ Start-Process - FilePath " takeown.exe" - ArgumentList " /f `" $dllPath `" " - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
72+
73+ # Grant full control to everyone
74+ Start-Process - FilePath " icacls.exe" - ArgumentList " `" $dllPath `" /grant *S-1-1-0:F" - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
75+
76+ # Rename file
77+ if (! (Test-Path $backupPath )) {
78+ Rename-Item - Path $dllPath - NewName " ${dll} _BAK.dll" - ErrorAction SilentlyContinue
79+ Write-Host " Renamed $dll .dll to ${dll} _BAK.dll"
80+
81+ # Restore ownership to TrustedInstaller
82+ Start-Process - FilePath " icacls.exe" - ArgumentList " `" $backupPath `" /setowner `" NT SERVICE\TrustedInstaller`" " - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
83+ Start-Process - FilePath " icacls.exe" - ArgumentList " `" $backupPath `" /remove *S-1-1-0" - Wait - WindowStyle Hidden - ErrorAction SilentlyContinue
84+ }
85+ }
86+ catch {
87+ Write-Host " Warning: Could not rename $dll .dll - $ ( $_.Exception.Message ) " - ForegroundColor Yellow
88+ }
89+ }
90+ }
2891
29- Write-Host " Setting $service StartupType to Disabled"
30- Get-Service - Name $service - ErrorAction SilentlyContinue | Set-Service - StartupType Disabled
92+ # Delete downloaded update files
93+ Write-Host " Cleaning up downloaded update files..." - ForegroundColor Yellow
94+
95+ try {
96+ $softwareDistPath = " C:\Windows\SoftwareDistribution"
97+ if (Test-Path $softwareDistPath ) {
98+ Get-ChildItem - Path $softwareDistPath - Recurse - Force | Remove-Item - Force - Recurse - ErrorAction SilentlyContinue
99+ Write-Host " Cleared SoftwareDistribution folder"
100+ }
31101 }
32- Write-Host " ================================="
33- Write-Host " --- Updates ARE DISABLED ---"
34- Write-Host " ================================="
102+ catch {
103+ Write-Host " Warning: Could not fully clear SoftwareDistribution folder - $ ( $_.Exception.Message ) " - ForegroundColor Yellow
104+ }
105+
106+ # Disable update related scheduled tasks
107+ Write-Host " Disabling update related scheduled tasks..." - ForegroundColor Yellow
108+
109+ $taskPaths = @ (
110+ ' \Microsoft\Windows\InstallService\*'
111+ ' \Microsoft\Windows\UpdateOrchestrator\*'
112+ ' \Microsoft\Windows\UpdateAssistant\*'
113+ ' \Microsoft\Windows\WaaSMedic\*'
114+ ' \Microsoft\Windows\WindowsUpdate\*'
115+ ' \Microsoft\WindowsUpdate\*'
116+ )
117+
118+ foreach ($taskPath in $taskPaths ) {
119+ try {
120+ $tasks = Get-ScheduledTask - TaskPath $taskPath - ErrorAction SilentlyContinue
121+ foreach ($task in $tasks ) {
122+ Disable-ScheduledTask - TaskName $task.TaskName - TaskPath $task.TaskPath - ErrorAction SilentlyContinue
123+ Write-Host " Disabled task: $ ( $task.TaskName ) "
124+ }
125+ }
126+ catch {
127+ Write-Host " Warning: Could not disable tasks in path $taskPath - $ ( $_.Exception.Message ) " - ForegroundColor Yellow
128+ }
129+ }
130+
131+ Write-Host " =================================" - ForegroundColor Green
132+ Write-Host " --- Updates ARE DISABLED ---" - ForegroundColor Green
133+ Write-Host " ===================================" - ForegroundColor Green
134+ Write-Host " Note: Some operations may require a system restart to take full effect." - ForegroundColor Yellow
35135}
0 commit comments