Advertisement
Guest User

Ras le bol de la mise à jour Windows 10 automatique !

a guest
Mar 17th, 2016
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Const HKLM = &h80000002
  2. Const HKCU = &H80000001
  3. Const DELETE = &h10000
  4.  
  5. Set sh = WScript.CreateObject("Wscript.Shell")
  6. Set objShell = CreateObject("Shell.Application")
  7.  
  8. repAppData = sh.ExpandEnvironmentStrings("%localappdata%")
  9. repTemp = sh.ExpandEnvironmentStrings("%TEMP%")
  10. repWindows = sh.ExpandEnvironmentStrings("%WINDIR%")
  11. strComputer = sh.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
  12.  
  13. Const HotFixID = "3035583"
  14.  
  15. kbURLxWin7x32 = "https://download.microsoft.com/download/C/5/3/C530B84C-857A-4296-BB9E-3BB59EEDF555/Windows6.1-KB3065987-v2-x86.msu"
  16. kbURLxWin7x64 = "https://download.microsoft.com/download/F/6/7/F678BB18-7D81-4BBA-8FED-6388FF7968AD/Windows6.1-KB3065987-v2-x64.msu"
  17. kbURLxWin8x32 = "https://download.microsoft.com/download/C/4/3/C43C4D83-A249-4026-9A36-1EB796957FA0/Windows8.1-KB3065988-v2-x86.msu"
  18. kbURLxWin8x64 = "https://download.microsoft.com/download/F/3/D/F3D9A5A4-75A3-47C8-971E-9D0D09AAF9DC/Windows8.1-KB3065988-v2-x64.msu"
  19.  
  20. kbNamexWin7x32 = "Windows6.1-KB3065987-v2-x86.msu"
  21. kbNamexWin7x64 = "Windows6.1-KB3065987-v2-x64.msu"
  22. kbNamexWin8x32 = "Windows8.1-KB3065988-v2-x86.msu"
  23. kbNamexWin8x64 = "Windows8.1-KB3065988-v2-x64.msu"
  24.  
  25. Set reg = GetObject("winmgmts://./root/default:StdRegProv")
  26. reg.CheckAccess HKLM, "SYSTEM\CurrentControlSet", DELETE, isAdmin
  27.  
  28. If Not isAdmin Then
  29.   ' Si les privileges ne sont pas eleves
  30.  
  31.   If WScript.Arguments.Count = 0 Then
  32.     ' Ouverture du script avec elevation de privileges
  33.    CreateObject("Shell.Application").ShellExecute WScript.FullName, _
  34.       Chr(34) & WScript.ScriptFullName & Chr(34) & " uac", _
  35.       sh.CurrentDirectory, "runas", 1
  36.     WScript.Quit 0
  37.   Else
  38.     WScript.Echo "Privilege elevation failed!"
  39.     WScript.Quit 1
  40.   End If
  41.  
  42. Else
  43.    
  44.     'Prerequis detection et unstallation KB3035583
  45.     HFStatus = CheckHotfixStatus(strComputer, HotFixID)
  46.     If HFStatus = False Then
  47.         sh.Popup "Le poste ne semble pas necessiter de manipulation", 30, "Fin du script"
  48.     Else
  49.         '0 creation point restauration systeme
  50.         createRestorePoint
  51.        
  52.         '1 desinstallation du kb en mode non silencieux
  53.         sh.run "taskkill /f /t /im gwx.exe"
  54.         strCmd = "wusa.exe /kb:3035583 /uninstall"
  55.         ReturnCode = ObjShell.Run(strCmd, 8, true)
  56.         If ReturnCode = 0 then
  57.             sh.Popup "Desinstallation de la mise a jour : Ok.", 5, "Desinstallation de mise a jour"
  58.         Else
  59.             'Error
  60.             sh.Popup "Desinstallation de la mise a jour : Erreur (Arret imminent du script)", 30, "Desinstallation de mise a jour"
  61.             wscript.quit
  62.         End If
  63.        
  64.         '2 on supprime le package du disque et les reps GWX
  65.         arrRepToDelete = Array(_
  66.             repWindows & "\system32\GWX", _
  67.             repWindows & "\syswow64\GWX", _
  68.             repAppData & "\GWX")
  69.         For Each RepToDelete In arrRepToDelete
  70.             sh.run "Takeown /F " & RepToDelete & " /r"
  71.             sh.run "icacls " & RepToDelete & " /t /grant Administrateur:F"
  72.             sh.run "rmdir /s /q " & RepToDelete & "\"
  73.         Next
  74.         strFilesToDelete = repWindows & "\servicing\packages\*KB3035583*.*"
  75.         sh.run "Takeown /F " & strFilesToDelete
  76.         sh.run "icacls " & strFilesToDelete & " /grant Administrateur:F"
  77.         sh.run "del " & strFilesToDelete
  78.         sh.Popup "Suppression des dossiers de GWX terminee", 5, "Nettoyage de GWX"
  79.        
  80.         '3 on bloque avec une policie la réinstallation de cette update
  81.         strCurrentOSVersion = CheckLocalOSVersion
  82.         Select Case strCurrentOSVersion
  83.             Case "1" 'Win7 - 32bits
  84.                 dlMyFile kbURLxWin7x32, kbNamexWin7x32
  85.                 ObjShell.Run "wusa.exe " & repTemp & "\" & kbNamexWin7x32
  86.  
  87.             Case "2" 'windows 7 64 bit
  88.                 dlMyFile kbURLxWin7x64, kbNamexWin7x64
  89.                 ObjShell.Run "wusa.exe " & repTemp & "\" & kbNamexWin7x64
  90.  
  91.             Case "3" 'windows 81 32 bit
  92.                 dlMyFile kbURLxWin8x32, kbNamexWin8x32
  93.                 ObjShell.Run "wusa.exe " & repTemp & "\" & kbNamexWin8x32
  94.  
  95.             Case "4" 'windows 81 64 bit
  96.                 dlMyFile kbURLxWin8x64, kbNamexWin8x64
  97.                 ObjShell.Run "wusa.exe " & repTemp & "\" & kbNamexWin8x64
  98.  
  99.             Case "5" 'inconnu
  100.         End Select
  101.        
  102.         '4 on bloque l icone en bas
  103.         DelGWXIcon
  104.        
  105.         '5 on supprime les taches planifiees GWX
  106.         strRepToAlter = repWindows & "\System32\Tasks\Microsoft\Windows\Setup\GWXTriggers"
  107.         ObjShell.Run "takeown /f " & strRepToModify & " /r"
  108.         ObjShell.Run "icacls " & strRepToModify & " /t /grant Administrateur:F"
  109.         arrGWXAndGWXTriggersTasks = Array(_
  110.             "gwx\launchtrayprocess", _
  111.             "gwx\refreshgwxconfig", _
  112.             "gwx\refreshgwxconfigandcontent", _
  113.             "gwx\refreshgwxcontent", _
  114.             "GWXTriggers\Logon-5d", _
  115.             "GWXTriggers\MachineUnlock-5d", _
  116.             "GWXTriggers\OutOfIdle-5d", _
  117.             "GWXTriggers\OutOfSleep-5d", _
  118.             "GWXTriggers\refreshgwxconfig-B", _
  119.             "GWXTriggers\ScheduleUpgradeReminderTime", _
  120.             "GWXTriggers\ScheduleUpgradeTime", _
  121.             "GWXTriggers\Time-5d")
  122.         For Each strTask In arrGWXAndGWXTriggersTasks
  123.             ObjShell.Run "schtasks /DELETE /TN Microsoft\Windows\Setup\" & strTask & " /F"
  124.         Next
  125.        
  126.         sh.Popup "La mise a jour vers Windows 10 est maintenant desactivee !", 30, "Fin du script"
  127.        
  128.     End If
  129. End If
  130.  
  131. Sub dlMyFile(myURL,myKbName)
  132.     dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
  133.     dim bStrm: Set bStrm = createobject("Adodb.Stream")
  134.     xHttp.Open "GET", myURL, False
  135.     xHttp.Send
  136.  
  137.     with bStrm
  138.         .type = 1 '//binary
  139.         .open
  140.         .write xHttp.responseBody
  141.         .savetofile repTemp & "\" & myKbName, 2 '//overwrite
  142.     end with
  143.     sh.Popup "Telechargement du patch termine", 5, "Telechargement"
  144. End Sub
  145.  
  146. Sub createRestorePoint
  147.     GetObject("winmgmts:\\.\root\default:Systemrestore").CreateRestorePoint "Avant desactivation de la mise a jour Windows 10", 0, 100
  148.     sh.Popup "Cree avec succes", 5, "Point de restauration Windows"
  149.     Exit Sub
  150. End Sub
  151.  
  152. Function CheckHotfixStatus(strComputer, strHotfixID)
  153.     Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  154.     if err.number <> 0 then
  155.         CheckParticularHotfix = "Impossible de se connecter au WMI"
  156.         exit function 'No reason to continue
  157.     end if
  158.    
  159.     strWMIforesp = "Select * from Win32_QuickFixEngineering where HotFixID = 'Q" & strHotfixID & "' OR HotFixID = 'KB" & strHotfixID & "'"
  160.     Set colQuickFixes = objWMIService.ExecQuery (strWMIforesp)
  161.     if err.number <> 0 Then 'if an error occurs
  162.         CheckParticularHotfix = "Impossible de trouver les informations WMI de cet Hotfix"
  163.     else 'Error number 0 meaning no error occured
  164.         tal = colQuickFixes.count
  165.         if tal > 0 then
  166.             CheckParticularHotfix = True    'HF installed
  167.         else
  168.             CheckParticularHotfix = False   'HF not installed
  169.         end If
  170.     end if
  171.     Set colQuickFixes = Nothing
  172.  
  173.     Err.Clear
  174.     On Error GoTo 0
  175. End Function
  176.  
  177. Function CheckLocalOSVersion
  178.     Dim OSVer, verbits
  179.     OSVer = sh.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")
  180.     verbits = sh.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
  181.     if OSVer = "6.1" AND verbits = "x86" then
  182.         CheckLocalOSVersion = 1 'win7 32 bit
  183.     Elseif OSVer = "6.1" AND verbits = "AMD64" then
  184.         CheckLocalOSVersion = 2 'win7 64 bit
  185.     Elseif OSVer = "6.3" AND verbits = "x86" then
  186.         CheckLocalOSVersion = 3 'win81 32 bit
  187.     Elseif OSVer = "6.3" AND verbits = "AMD64" then
  188.         CheckLocalOSVersion = 4 'win81 64 bit
  189.     else
  190.         wscript.Echo "os inconnu"
  191.         CheckLocalOSVersion = 5 'inconnu
  192.     end If
  193. End Function
  194.  
  195. Sub DelGWXIcon
  196.     Dim RegLocate, RegLocate1
  197.     RegLocate = "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\GWX\DisableGwx"
  198.     sh.RegWrite RegLocate,"1","REG_DWORD"
  199.     RegLocate1 = "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\DisableOSUpgrade"
  200.     sh.RegWrite RegLocate1,"1","REG_DWORD"
  201.     Exit Sub
  202. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement