Bloquer le Adware GWX Windows 10 par script VBSCRIPT

Bloquer le Adware GWX Windows 10 par script VBSCRIPT

Bloquer le Adware GWX Windows 10 par script VBSCRIPT

2 commentaires sur Bloquer le Adware GWX Windows 10 par script VBSCRIPT 22 155 views

La Pub de Windows 10 devient très chiante, j’ai donc scripté la désinstallation totale de ce Adware pour Windows 7 et 8.1 français.
Ce script est le plus complet que vous trouverez sur le net, il fait tout ce qui suit:
-test si le KB3035583 de Windows 10 est présent
-crée un point de restauration
-tue la tache GWX
-supprime les fichiers GWX et package
-désinstallation du KB3035583
-suppression de l’icone GWX
-installation du KB correspondant pour bloquer la reinstallation de ce KB (je ne cache pas le KB3035583)
-suppression des taches planifiées installées par GWX (souvent c’est oublié ce truc)

Le code source du vbs est ici, si vous avez des bugs signalez moi. J’ai attaché un auto-exe avec les MSUs, enjoy…

blocker-windows10-V3

To use it for English or other localized Windows, just download your update KB corresponding for blocking futur W10 update. In the vbs modify msu titles.

' VBscript suppression W10 update french
' FRENCHYTECH - JM SAILLIO – 2016
' version 2.0
'*****************************************************
On Error Resume Next

'variables
dim vAPPDATA, vTEMP, vWINDIR, WshShell, Return, ReturnCode, objShell

'constantes
Const HotFixID = "3035583"

' variables globales
Set WshShell = WScript.CreateObject("Wscript.Shell")

'chemin classique pour rep temp
vAPPDATA = WshShell.ExpandEnvironmentStrings("%localappdata%")
vTEMP = WshShell.ExpandEnvironmentStrings("%TEMP%")
vWINDIR = WshShell.ExpandEnvironmentStrings("%WINDIR%")
strputer = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )

'passe le script en mode admin

If WScript.Arguments.Count = 0 Then
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " Run", , "runas", 1
Else

'Prerequis detection et unstallation KB3035583

status = CheckParticularHotfix(strputer, HotFixID)
'si KB installe c est parti
If status = true then
wscript.Echo "The Microsoft KB" & HotFixID & " est installé, on lance la proc."

'0 creation point restau

Call creapointrestau

'1 desinstallation du kb en mode non silencieux

Set objShell = CreateObject("WScript.Shell")
ObjShell.Run "taskkill /f /t /im gwx.exe"
strCmd1 = "wusa.exe /kb:3035583 /uninstall"
WScript.Echo "Commandline: " & strCmd1
ReturnCode = objShell.Run(strCmd1, 8, true)
If ReturnCode = 0 then
wscript.Echo "desinstallation faite du KB. On continue press enter"
else
'Error
wscript.Echo "impossible de desinstaller le kb, on quitte"
wscript.quit
end if

'2 on supprime le package du disque et les reps GWX

'on prend le ownership sur les reps et on efface GWX partout

objShell.Run "takeown /F c:\windows\system32\GWX /r"
objShell.Run "takeown /F c:\windows\syswow64\GWX /r"
objShell.Run "takeown /F c:\windows\servicing\packages\*KB3035583*.*"
objShell.Run "takeown /f " & vAPPDATA & "\GWX /r"
objShell.Run "takeown /f " & vAPPDATA & "\GWX /r"
objShell.Run "icacls c:\windows\system32\GWX /t /grant Administrateur:D"
objShell.Run "icacls c:\windows\syswow64\GWX /t /grant Administrateur:D"
objShell.Run "icacls c:\windows\servicing\packages\*KB3035583*.* /grant Administrateur:D"
objShell.Run "icacls "& vAPPDATA & "\GWX /t /grant administrateur:F"
objShell.Run "rmdir /s /q c:\windows\system32\GWX\"
objShell.Run "rmdir /s /q c:\windows\syswow64\GWX\"
objShell.Run "del c:\windows\servicing\packages\*KB3035583*.*"
objShell.Run "rmdir /s /q " & vAPPDATA & "\GWX\"
wscript.Echo "OK suppressions des fichiers locaux termines"

'3 on bloque avec une policie la réinstallation de cette update

strCurrentOSVersion = CheckLocalOSVersion
Select Case strCurrentOSVersion
Case "1" 'Win7 - 32bits
objShell.Run "wusa.exe " & vTEMP & "\Windows6.1-KB3065987-v2-x86.msu"

Case "2" 'windows 7 64 bit
objShell.Run "wusa.exe " & vTEMP & "\Windows6.1-KB3065987-v2-x64.msu"

Case "3" 'windows 81 32 bit
objShell.Run "wusa.exe " & vTEMP & "\Windows8.1-KB3065988-v2-x86.msu"

Case "4" 'windows 81 64 bit
objShell.Run "wusa.exe " & vTEMP & "\Windows8.1-KB3065988-v2-x64.msu"

Case "5" 'inconnu
End Select

'4 on bloque l icone en bas
CALL suppiconew10

'5 on supprime les taches planifiees GWX
objShell.Run "schtasks /DELETE /TN Microsoft\Windows\Setup\gwx\launchtrayprocess /F"
objShell.Run "schtasks /DELETE /TN Microsoft\Windows\Setup\gwx\refreshgwxconfig /F"
objShell.Run "schtasks /DELETE /TN Microsoft\Windows\Setup\gwx\refreshgwxconfigandcontent /F"
objShell.Run "schtasks /DELETE /TN Microsoft\Windows\Setup\gwx\refreshgwxcontent /F"

objShell.Run "takeown /f C:\Windows\System32\Tasks\Microsoft\Windows\Setup\GWXTriggers /r && icacls C:\Windows\System32\Tasks\Microsoft\Windows\Setup\GWXTriggers /t /grant Administrateur:F"
objShell.Run "schtasks /DELETE /TN Microsoft\Windows\Setup\GWXTriggers\Logon-5d /F"
objShell.Run "schtasks /DELETE /TN Microsoft\Windows\Setup\GWXTriggers\MachineUnlock-5d /F"
objShell.Run "schtasks /DELETE /TN Microsoft\Windows\Setup\GWXTriggers\OutOfIdle-5d /F"
objShell.Run "schtasks /DELETE /TN Microsoft\Windows\Setup\GWXTriggers\OutOfSleep-5d /F"
objShell.Run "schtasks /DELETE /TN Microsoft\Windows\Setup\GWXTriggers\refreshgwxconfig-B /F"
objShell.Run "schtasks /DELETE /TN Microsoft\Windows\Setup\GWXTriggers\ScheduleUpgradeReminderTime /F"
objShell.Run "schtasks /DELETE /TN Microsoft\Windows\Setup\GWXTriggers\ScheduleUpgradeTime /F"
objShell.Run "schtasks /DELETE /TN Microsoft\Windows\Setup\GWXTriggers\Time-5d /F"

wscript.Echo "c est fini windows 10 mon pote"

Elseif status = false Then
wscript.Echo "Le KB" & HotFixID & " n est pas installé"
wscript.quit
else
'Error
wscript.Echo "Erreur, impossible de vérifier le Microsoft KB. Erreur is: " & status
wscript.quit
end if

End If

private Function CheckParticularHotfix(strPuter, strHotfixID)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Version 1.0
' Checks if a particular hotfix is installed or not.
' This function has these 3 return options:
' TRUE, FALSE,
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
On error resume next
dim objWMIService
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strPuter & "\root\cimv2")
if err.number <> 0 then
CheckParticularHotfix = "WMI could not connect to computer '" & strPuter & "'"
exit function 'No reason to continue
end if

strWMIforesp = "Select * from Win32_QuickFixEngineering where HotFixID = 'Q" & strHotfixID &_
"' OR HotFixID = 'KB" & strHotfixID & "'"
Set colQuickFixes = objWMIService.ExecQuery (strWMIforesp)
if err.number <> 0 Then 'if an error occurs
CheckParticularHotfix = "Unable to get WMI hotfix info"
else 'Error number 0 meaning no error occured
tal = colQuickFixes.count
if tal > 0 then
CheckParticularHotfix = True 'HF installed
else
CheckParticularHotfix = False 'HF not installed
end If
end if
Set colQuickFixes = Nothing

Err.Clear
On Error GoTo 0
end function

Function CheckLocalOSVersion
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Version 1.0
' os version est 32 bit ou 64 bit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim objShell1, OSVer, verbits
Set objShell1 = CreateObject("Wscript.Shell")
OSVer = objShell1.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")
verbits = objShell1.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
if OSVer = "6.1" AND verbits = "x86" then
CheckLocalOSVersion = 1 'win7 32 bit
Elseif OSVer = "6.1" AND verbits = "AMD64" then
CheckLocalOSVersion = 2 'win7 64 bit
Elseif OSVer = "6.3" AND verbits = "x86" then
CheckLocalOSVersion = 3 'win81 32 bit
Elseif OSVer = "6.3" AND verbits = "AMD64" then
CheckLocalOSVersion = 4 'win81 64 bit
else
wscript.Echo "os inconnu"
CheckLocalOSVersion = 5 'inconnu
end If

End Function

Sub suppiconew10
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Version 1.0
' ecriture de 2 cles pour l icone et l update w10
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim objShell2, RegLocate, RegLocate1
Set objShell2 = WScript.CreateObject("WScript.Shell")
On Error Resume Next
RegLocate = "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\GWX\DisableGwx"
objShell2.RegWrite RegLocate,"1","REG_DWORD"
RegLocate1 = "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\DisableOSUpgrade"
objShell2.RegWrite RegLocate1,"1","REG_DWORD"
Exit Sub
End Sub

Sub creapointrestau
dim objShell3
Set objShell3 = CreateObject("Shell.Application")
GetObject("winmgmts:\\.\root\default:Systemrestore").CreateRestorePoint InputBox("Entrer une description pour le point de restauration:","Create Restore Point - Forum-Seven.com"), 0, 100
Msgbox("Point de restauration créé!")

Exit Sub
End Sub

About the author:

Ingénieur ENSEA, 15 ans Manager IT Support pour des grands comptes, maintenant Indépendant au sein de FRENCHYTECH, conseil en SI pour PME/TPE

2 Commentaires

  1. Letouane  - 18 mars 2016 - 4 h 40 min

    Salut, merci pour ton script qui semble correspondre à mes attentes : j’en ai marre que les PC de mes clients passent à Windows 10 automatiquement car une migration de système ça se prévoit et ça n’est pas sans conséquences.
    Par contre j’ai un peu adapté ton script :
    – Téléchargement automatique du fichier MSU selon la version de Windows à patcher.
    – Suppression des lignes en trop (genre “On error resume” et objShell : on le fait une et une seule fois ça suffit).
    – Optimisation de l’usage des variables d’environnement.
    – Utilisation de tableaux pour traiter les opérations par lots plutôt qu’à la mode CMD.
    – Modification de certains noms de variable/fonction.

    Il resterait encore à optimiser tout cela en utilisant les vraies commandes VBScript pour la modification de propriétaire et l’attribution des droits mais je pinaille là 😉

    Voici le lien de ma version (pas testée au moment de l’envoi mais l’idée est là) :
    http://pastebin.com/tKup8uiy

    • JM SAILLIO  - 27 mars 2016 - 11 h 00 min

      Merci @letouane de partager ton script. Je regarde ça en détails.

Laisser un commentaire

retour en haut