From bea2b01cfb41e7f06a1fb49818b32ecdb73ac7a8 Mon Sep 17 00:00:00 2001 From: Yorick Date: Wed, 27 Jan 2016 15:06:38 +0100 Subject: [PATCH 1/8] Reworked remove_task for Windows 7 compatibility --- remove-kb.ps1 | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/remove-kb.ps1 b/remove-kb.ps1 index 25f277c..e476d3a 100755 --- a/remove-kb.ps1 +++ b/remove-kb.ps1 @@ -11,28 +11,45 @@ $kbIDs=("KB3075249", #telemetry for Win7/8.1 "KB2876229", "KB2953664" ) - $sheduledTasks=( - "launchtrayprocess", - "refreshgwxconfig", - "refreshgwxconfigandcontent", - "regreshgwxcontent" + @{name = "launchtrayprocess"; directory = "\Microsoft\Windows\Setup\GWX"}, + @{name = "refreshgwxconfig"; directory = "\Microsoft\Windows\Setup\GWX"}, + @{name = "refreshgwxconfigandcontent"; directory = "\Microsoft\Windows\Setup\GWX"}, + @{name = "regreshgwxcontent"; directory = "\Microsoft\Windows\Setup\GWX"} ) function remove_tasks () { param($taskList) Foreach ($task in $taskList){ - Write-Host -ForegroundColor white -NoNewline "Remove Task " $task - if (Get-ScheduledTask -TaskName $task -ErrorAction SilentlyContinue) { - Write-Host -NoNewline -ForegroundColor DarkGreen " found! " - Write-Host -Nonewline -ForegroundColor white "removing ... " - Try {Unregister-ScheduledTask -TaskName $task -ErrorAction SilentlyContinue -Confirm:$false} - Catch { - Write-Host -Nonewline -ForegroundColor white " Error " + Write-Host -ForegroundColor white -NoNewline "Remove Task " $task.name + if ($PSVersionTable.PSVersion.Major > 2) { + if (Get-ScheduledTask -TaskName $task.name -ErrorAction SilentlyContinue) { + Write-Host -NoNewline -ForegroundColor DarkGreen " found! " + Write-Host -Nonewline -ForegroundColor white "removing ... " + Try {Unregister-ScheduledTask -TaskName $task.name -ErrorAction SilentlyContinue -Confirm:$false} + Catch { + Write-Host -Nonewline -ForegroundColor white " Error " + } + Write-Host -ForegroundColor Green " Done" } - Write-Host -ForegroundColor Green "Done" + else { Write-Host -ForegroundColor Yellow " Already removed"} + } + else { + $currentTask = $task.directory + "\" + $task.name + if(schtasks /Query /TN $currentTask 2>$null) { + Write-Host -NoNewline -ForegroundColor DarkGreen " found! " + Write-Host -Nonewline -ForegroundColor white "removing ... " + try{ + echo $yes | schtasks /Delete /TN $currentTask /F 2>$null + } + Catch { + Write-Host -Nonewline -ForegroundColor white " Error " + } + Write-Host -ForegroundColor green "Done" + + } + else { Write-Host -ForegroundColor Yellow " Already removed"} } - else { Write-Host -ForegroundColor Yellow "Already removed"} } } From 0d22769974692a52199cdeb27a55f8d05b3d0f0d Mon Sep 17 00:00:00 2001 From: Yorick Date: Wed, 27 Jan 2016 16:00:13 +0100 Subject: [PATCH 2/8] Change comparaison operator fot powershell Major Version (remove_tasks) --- remove-kb.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remove-kb.ps1 b/remove-kb.ps1 index e476d3a..2701cfb 100755 --- a/remove-kb.ps1 +++ b/remove-kb.ps1 @@ -22,7 +22,7 @@ function remove_tasks () { param($taskList) Foreach ($task in $taskList){ Write-Host -ForegroundColor white -NoNewline "Remove Task " $task.name - if ($PSVersionTable.PSVersion.Major > 2) { + if ($PSVersionTable.PSVersion.Major -gt 2) { if (Get-ScheduledTask -TaskName $task.name -ErrorAction SilentlyContinue) { Write-Host -NoNewline -ForegroundColor DarkGreen " found! " Write-Host -Nonewline -ForegroundColor white "removing ... " From 0a5ca4f921a81d7bd5a8e7cd4ca8bb4013ecb6a3 Mon Sep 17 00:00:00 2001 From: Yorick Date: Wed, 27 Jan 2016 16:22:14 +0100 Subject: [PATCH 3/8] remove comment before wusa line --- remove-kb.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remove-kb.ps1 b/remove-kb.ps1 index 2701cfb..99b74b0 100755 --- a/remove-kb.ps1 +++ b/remove-kb.ps1 @@ -89,7 +89,7 @@ Foreach($kbID in $kbIDs){ if (Get-HotFix -Id $kbID -ErrorAction SilentlyContinue){ Write-Host -NoNewline -ForegroundColor DarkGreen "found! " Write-Host -Nonewline -ForegroundColor white "removing ... " - #wusa.exe /uninstall /KB:$kbNum /norestart /quiet + wusa.exe /uninstall /KB:$kbNum /norestart /quiet Do { Start-Sleep -Seconds 3 From 109be998e1b100a7d9aca2d7cc93da9052abe359 Mon Sep 17 00:00:00 2001 From: Yorick Date: Wed, 27 Jan 2016 16:44:12 +0100 Subject: [PATCH 4/8] Reworked GWX process detection --- remove-kb.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/remove-kb.ps1 b/remove-kb.ps1 index 99b74b0..26ce96d 100755 --- a/remove-kb.ps1 +++ b/remove-kb.ps1 @@ -79,9 +79,15 @@ function hide_update() { if (!$found){ Write-Host -ForegroundColor Red "Not found"} } } -if (stop-process -name GWX -Force -ErrorAction SilentlyContinue) { - Write-Host "GWX process stopped ..." + +Write-Host -Nonewline -ForegroundColor white "Searching gor GWX process ... " +if (Get-Process -name GWX -ErrorAction SilentlyContinue}) { + Write-Host -ForegroundColor DarkGreen -NoNewLine "Running " + Write-Host -Nonewline -ForegroundColor white "removing ... " + Try {Stop-Process -name GWX -Force -ErrorAction SilentlyContinue} + Catch { Write-Host -ForegroundColor Red "Error"} } +else { Write-Host -ForegroundColor Yellow ("Not running")} Foreach($kbID in $kbIDs){ $kbNum = $kbID.Replace("KB","") From cb026949eab28f54d660822a07d2e72c716e482b Mon Sep 17 00:00:00 2001 From: Yorick Date: Wed, 27 Jan 2016 16:54:02 +0100 Subject: [PATCH 5/8] update README --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3c62200..3afd525 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,19 @@ Because I'm a Linux fan and this is my first try with powershell this script is really simple and could not work properly, burn your cat and cut your Little Pony head. +#How? + +This script kill GWX executable, then remove some Scheduled Task about +GWX program, uninstall some KB with wusa.exe and hide it to prevent automatic +reinstallation. + #TODO - * Add privilege elevation error when the script is not launched with Administrator's rights - * Add the possibility to use arguments when calling the script (then ps script could be call from - another script) + * Add privilege elevation error when the script is not launched with + Administrator's rights + * Add the possibility to use arguments when calling the script (then ps script + could be call from another script) + * Remove GWX Files before uninstalling KB (check remove_gwx_file branch) * ~~Update the windows update list to hide kb that aren't yet listed~~ * ~~Speed up hide_update~~ * **Tell me** From 155b5dbc800f65f84cb2cccfd7451f7f53d7a50c Mon Sep 17 00:00:00 2001 From: Yorick Date: Tue, 2 Feb 2016 17:57:48 +0100 Subject: [PATCH 6/8] Fix sheduled task name --- remove-kb.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remove-kb.ps1 b/remove-kb.ps1 index 26ce96d..ebb9bf3 100755 --- a/remove-kb.ps1 +++ b/remove-kb.ps1 @@ -15,7 +15,7 @@ $sheduledTasks=( @{name = "launchtrayprocess"; directory = "\Microsoft\Windows\Setup\GWX"}, @{name = "refreshgwxconfig"; directory = "\Microsoft\Windows\Setup\GWX"}, @{name = "refreshgwxconfigandcontent"; directory = "\Microsoft\Windows\Setup\GWX"}, - @{name = "regreshgwxcontent"; directory = "\Microsoft\Windows\Setup\GWX"} + @{name = "refreshgwxcontent"; directory = "\Microsoft\Windows\Setup\GWX"} ) function remove_tasks () { From 15c839f3502f70fc4866e824df6498ff8a0134cc Mon Sep 17 00:00:00 2001 From: Yorick Date: Tue, 2 Feb 2016 18:06:26 +0100 Subject: [PATCH 7/8] Add som KB to remove / hide thanks to https://fix10.isleaked.com/oldwindows.html --- remove-kb.ps1 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/remove-kb.ps1 b/remove-kb.ps1 index ebb9bf3..f9c9fd8 100755 --- a/remove-kb.ps1 +++ b/remove-kb.ps1 @@ -1,4 +1,5 @@ -$kbIDs=("KB3075249", #telemetry for Win7/8.1 +$kbIDs=("KB2976978", #telemetry for Win8/8.1 + "KB3075249", #telemetry for Win7/8.1 "KB3080149", #telemetry for Win7/8.1 "KB3021917", #telemetry for Win7 "KB3022345", #telemetry @@ -7,8 +8,11 @@ $kbIDs=("KB3075249", #telemetry for Win7/8.1 "KB3035583", #Get Windows 10 for Win7sp1/8.1 "KB2990214", #Get Windows 10 for Win7 without sp1 "KB2952664", #Get Windows 10 assistant - "KB2976978", - "KB2876229", + "KB3075853", #Update on Win8.1/Server 2012R2 + "KB3065987", #Update for Windows Update on Win7/Server 2008R2 + "KB3050265", #Update for Windows Update on Win7 + "KB3075851", #Update for Windows Update on Win7 + "KB2902907", "KB2953664" ) $sheduledTasks=( From 43e228cb530c8abdc03ff1599af33bf34dcf8d45 Mon Sep 17 00:00:00 2001 From: Yorick Date: Tue, 2 Feb 2016 18:07:51 +0100 Subject: [PATCH 8/8] Message correction --- remove-kb.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remove-kb.ps1 b/remove-kb.ps1 index f9c9fd8..502e33e 100755 --- a/remove-kb.ps1 +++ b/remove-kb.ps1 @@ -84,7 +84,7 @@ function hide_update() { } } -Write-Host -Nonewline -ForegroundColor white "Searching gor GWX process ... " +Write-Host -Nonewline -ForegroundColor white "Searching for GWX process ... " if (Get-Process -name GWX -ErrorAction SilentlyContinue}) { Write-Host -ForegroundColor DarkGreen -NoNewLine "Running " Write-Host -Nonewline -ForegroundColor white "removing ... "