提醒:本页面将不再更新、维护或者支持,文章、评论所叙述内容存在时效性,涉及技术细节或者软件使用方面不保证能够完全有效可操作,请谨慎参考!

去年7月写过一篇 文章 讲解如何去除扰人的获取Windows 10的图标,那时候微软也只是推送了获取Windows 10的提示,具体安装Windows 10与否还是有显著的选项让用户自己选择的。

虽然通过先前的方法确实抑制了升级Windows 10的提示,怎奈微软接下来连续放大招推送升级补丁,并且不怎么明显的“诱使”用户升级系统,比如我遇到的微软健康助手提示升级,并且默认勾选同意的坑。其实我不是说Windows 10不好,就是较为反感微软的推送方式,就好像你去商场老是有业务员跟着你,不停向你推荐某某产品好等等,而且因为大部分客户电脑上一些业务系统在Windows 10下存在各种兼容问题,就有客户反应因为不小心升级Windows 10导致业务软件不能正常运行最后只有重新安装老系统 (其实对于误安装有办法直接恢复到老系统,方法附本文后)

第一部分,如何防止Windows 7/8/8.1升级到Windows 10

经常有朋友说我思想老顽固了,不愿意去尝试新鲜事物,其实不是不愿意尝试,而是越来越觉得适合自己的才是最好的,不喜欢繁杂的功能,觉得简单才是一种美,好了言归正传,防止老系统升级到Windows 10实际上已经有人开发了软件 GWX Control Panel ,大家直接 下载 后运行,再点击即可防止系统升级,用这个软件还有个好处就是可以在想升级的时候再进行恢复,软件简单操作如下。

1、运行下载的GWX Control Panel程序,首先接受并同意须知,如下图所示:

GWX Control Panel - Step 1

2、点击“Prevent Automatic Windows 10 Upgrades”即可禁止自动的Windows 10升级,其他的选项也有特定含义,主要的我翻译如下图所示:

GWX Control Panel - Step 2

其实对于快餐族或者实用主义者来说GWX Control Panel已经足够,所以下面的内容可以忽略,但是我有一颗重复造轮子的心,遂根据我收集的关于禁止升级到Windows 10的相关文献资料,对于禁止升级到Windows 10,大体上分为以下几个步骤:

1、卸载并且隐藏关联更新,这些更新主要包括如下:

通过以下批处理可以完成相关卸载,另存为.bat文件,并右击以管理员身份运行:

@echo on
wusa /uninstall /kb:3035583 /norestart /quiet
wusa /uninstall /kb:3022345 /norestart /quiet
wusa /uninstall /kb:3068708 /norestart /quiet
wusa /uninstall /kb:3075249 /norestart /quiet
wusa /uninstall /kb:3080149 /norestart /quiet
wusa /uninstall /kb:2990214 /norestart /quiet
wusa /uninstall /kb:3012973 /norestart /quiet
wusa /uninstall /kb:2952664 /norestart /quiet
wusa /uninstall /kb:2976978 /norestart /quiet

隐藏相关更新项目,以避免再一次被推送安装,如何 隐藏Windows更新 ,可以通过以下步骤来实现:

(1) 控制面板 - 所有控制面板项 - Windows Update 点击如下图位置(不完全一样,位置相同)找到待更新的项目:

Windows Update

(2) 对更新项目右击,选择“隐藏更新”即可,如下图所示:

Windows Update 隐藏更新

2、修改相关注册表

将下面的注册表相关另存为.reg文件,并且双击导入即可完成修改:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\OSUpgrade]
"AllowOSUpgrade"=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\OSUpgrade\State]
"OSUpgradeState"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate]
"DisableOSUpgrade"=dword:00000001

3、删除相关文件

删除 %SystemRoot%\System32\GWX 目录及相关文件,通过以下批处理完成:

del /f /s /a /q %SystemRoot%\System32\GWX

删除已经下载的Windows 10安装包及相关文件,通过以下批处理完成:

del /f /s /a /q %SystemDrive%\$Windows.~BT
del /f /s /a /q %SystemDrive%\$Windows.~WS

这里解释一下, $WINDOWS.~BT 文件夹内容是Windows10预下载镜像,这个文件夹很大因为包含了一个操作系统嘛; $Windows.~WS 文件夹是下载工具MediaCreationTool下载的文件夹,默认保留原先旧系统31天,其实并不建议大家通过以上批处理完成清理过程,可以通过系统自带的“磁盘清理工具”来清理比较好。

磁盘清理工具

经过这么一折腾,你的Windows 7/8/8.1又将恢复安静了,至于什么时候安装Windows 10则完全由个人决定,而不是每天都有人催促和推销(M$表打我)。当然我希望这个过程能够越快越好和越简单越好,对于业余系统维护人员来说,客户电脑越稳定自己要做的工作越少,花费的时间也越少,所以不希望有客户误点升级导致业务软件失效,所以我将上述功能打包成VBScript可执行脚本,只要在不可以升级的系统上运行即可免去误升级的烦恼, 当然脚本由于个人能力有限可能存在潜在的Bug,因此带来的问题与本人无关,建议使用前备份相关文件

'
' File Description : Disable Windows 7/8/8.1 Upgrade to Windows 10
'
' Copyright (c) 2016 WangYe. All rights reserved.
' 
' Author: WangYe
' Site: http://wangye.org
' This code is distributed under the BSD license
'
' Usage:
'     CScript path/to/this/script
'
' *** 请不要移除此版权信息 ***
'

Option Explicit

Class WinUpdateMgr

    Private objSession
    Private objCollection
    
    Private Sub Class_Initialize()
        Set objSession = WScript.CreateObject("Microsoft.Update.Session")
        objSession.ClientApplicationID = "Disable Windows 10 Update Script"
        Set objCollection = WScript.CreateObject("Microsoft.Update.UpdateColl")
    End Sub

    Private Sub Class_Terminate()
        Set objCollection = Nothing
        Set objSession = Nothing
    End Sub
    
    Public Sub AddToCollection(ByRef objUpdateItem)
        objCollection.Add objUpdateItem
    End Sub
    
    Public Sub ClearCollection()
        objCollection.Clear
    End Sub
    
    Public Function GetCollectionCount()
        GetCollectionCount = objCollection.Count
    End Function
    
    Public Function Install()
        If objCollection.Count > 0 Then
            Dim objInstaller
            Set objInstaller = objSession.CreateUpdateInstaller()
                objInstaller.Updates = objCollection
                Set Install = objInstaller.Install()
                ClearCollection
            Set objInstaller = Nothing
        End If
    End Function
    
    Public Function Uninstall()
        If objCollection.Count > 0 Then
            Dim objInstaller
            Set objInstaller = objSession.CreateUpdateInstaller()
                objInstaller.Updates = objCollection
                Set Uninstall = objInstaller.Uninstall()
                ClearCollection
            Set objInstaller = Nothing
        End If
    End Function
    
    Public Function EnumUpdates(ByVal strCallback, ByVal strQuery, ByRef Param)
        Dim i
        Dim objSearcher, objSearchResult, objUpdateItem
        Dim fnCallback
        
        Set fnCallback = GetRef(strCallback)
        Set objSearcher = objSession.CreateUpdateSearcher()
        Set objSearchResult = objSearcher.Search(strQuery)

        For i = 0 To objSearchResult.Updates.Count - 1
            Set objUpdateItem = objSearchResult.Updates.Item(i)
            if fnCallback(objUpdateItem, Me, Param) Then Exit For
            Set objUpdateItem = Nothing
        Next
        
        Set objSearcher = Nothing
        Set objSearchResult = Nothing
        Set fnCallback = Nothing
        
        EnumUpdates = i
    End Function
    
End Class

' KB2990967 and KB3035583
Function RemoveUpdateCallback(ByRef objItem, ByRef objThis, ByRef Param)
    Dim i, kbArticleId
    For i = 0 To objItem.KBArticleIDs.Count - 1
        kbArticleId = objItem.KBArticleIDs(i)
        If InStr("," & Param & ",", "," & kbArticleId & ",") Then
            WSH.StdOut.Write "Found " & objItem.Title & " ... "
            If objItem.IsInstalled Then
                WSH.StdOut.Write "Installed"
                WSH.StdOut.Write vbCrLf
                objThis.AddToCollection objItem
            Else
                WSH.StdOut.Write "Not Installed"
                WSH.StdOut.Write vbCrLf
            End If
            
            WSH.StdOut.Write " * Hiding this update now ... "
            objItem.IsHidden = True
            WSH.StdOut.Write " Completed" & vbCrLf
        End If
    Next
End Function

Sub RemoveWinUpdates()
    Dim objWUMgr, objUninstallResult
    Set objWUMgr = New WinUpdateMgr

        WSH.Echo "Please wait for checking Windows updates ..."
        
        objWUMgr.EnumUpdates "RemoveUpdateCallback", "Type='Software'", _
            "3035583,2952664,3022345,3021917,3068708,3075249,3080149,2990214,3012973,2976978"
        WSH.Echo "---------- Check Completed -----------"
        
        If objWUMgr.GetCollectionCount() > 0 Then
        
            WSH.Echo "Please wait for uninstall Windows updates ..."
            Set objUninstallResult = objWUMgr.Uninstall()
            WSH.Echo "Uninstall completed (ResultCode = " & objUninstallResult.ResultCode & ")"
            If objUninstallResult.RebootRequired > 0 Then
                WSH.Echo "You need restart computer for complete uninstall steps"
            End If
            Set objUninstallResult = Nothing
            
        End If
        WSH.Echo
    Set objWUMgr = Nothing
End Sub

Sub UpdateRegistry()
    Const HKLM = &H80000002
    Dim strComputer, objRegistry, strKeyPath
    
    WSH.Echo "Update registry now ..."
    strComputer = "."
    Set objRegistry = GetObject("winmgmts:\\" & _
            strComputer & "\root\default:StdRegProv")
            
    strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\OSUpgrade"
    objRegistry.CreateKey HKLM, strKeyPath
    objRegistry.SetDWORDValue HKLM, strKeyPath, "AllowOSUpgrade", 0
    
    strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\OSUpgrade\State"
    objRegistry.CreateKey HKLM, strKeyPath
    objRegistry.SetDWORDValue HKLM, strKeyPath, "OSUpgradeState", 1
    
    strKeyPath = "SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
    objRegistry.CreateKey HKLM, strKeyPath
    objRegistry.SetDWORDValue HKLM, strKeyPath, "DisableOSUpgrade", 1
    
    strKeyPath = "SOFTWARE\Policies\Microsoft\Windows\Gwx"
    objRegistry.CreateKey HKLM, strKeyPath
    objRegistry.SetDWORDValue HKLM, strKeyPath, "DisableGwx", 1
    
    WSH.Echo "--------- Update Completed -----------"
    WSH.Echo
    Set objRegistry = Nothing
End Sub

Sub DeleteAll(ByRef fso, ByVal strFileName)
    Const DeleteReadonly = True
    Dim objFile, objFolder, objSubFolder
    
    If fso.FileExists(strFileName) Then
        fso.DeleteFile strFileName, True
        Exit Sub
    End If
    
    If fso.FolderExists(strFileName) Then
        Set objFolder = fso.GetFolder(strFileName)
        
        fso.DeleteFile(fso.BuildPath(objFolder.Path, "*")), DeleteReadonly
        fso.DeleteFolder(fso.BuildPath(objFolder.Path, "*")),DeleteReadonly
        
        For Each objFile In objFolder.Files
           On Error Resume Next
           objFile.Delete True
           On Error GoTo 0
        Next
        For Each objSubFolder In objFolder.SubFolders
           On Error Resume Next
           objSubFolder.Delete True
           On Error GoTo 0
        Next
        
        objFolder.Delete True
        
        Set objFolder = Nothing
    End If
   
End Sub

Sub DeleteFiles()
    Const WindowsFolder = 0
    Const SystemFolder  = 1
    
    WSH.Echo "Please wait for Clean up unwanted folders or files ..."
    WSH.Echo "--------------------------------------"
    
    Dim objFileSysObj, objFile, strRootDir, strFileName
    Set objFileSysObj = WScript.CreateObject("Scripting.FileSystemObject") 
    
    WSH.Echo "Clean up GWX folder ..."
    Set objFile = objFileSysObj.GetSpecialFolder(SystemFolder)
    strFileName = objFileSysObj.BuildPath(objFile.Path, "GWX")
    DeleteAll objFileSysObj, strFileName
    Set objFile = Nothing
    
    WSH.Echo "Clean up Downloaded Windows 10 folder ..."
    Set objFile = objFileSysObj.GetSpecialFolder(WindowsFolder)
        strRootDir = objFileSysObj.GetParentFolderName(objFile.Path)
        strFileName = objFileSysObj.BuildPath(strRootDir, "$Windows.~BT")
        DeleteAll objFileSysObj, strFileName
        strFileName = objFileSysObj.BuildPath(strRootDir, "$Windows.~WS")
        DeleteAll objFileSysObj, strFileName
    Set objFile = Nothing
    
    WSH.Echo "--------- Clean up Completed ---------"
    WSH.Echo
    Set objFileSysObj = Nothing
End Sub

Sub TerminateProcess(ByVal strProcName)
    Const strComputer = "." 
    Dim objWMIService, colProcessList, objProcess
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & strProcName & "'")
    For Each objProcess in colProcessList 
        objProcess.Terminate()
    Next
End Sub

Sub KillProcesses()
    WSH.Echo "Terminate process now ..."
    
    WSH.Echo "Kill GWX in process list ..."
    TerminateProcess "GWX.exe"
    TerminateProcess "GWXUX.exe"
    TerminateProcess "Gwxgc.exe"
    TerminateProcess "Gwxconfigmanager.exe"
    TerminateProcess "Gwxdetector.exe"
    TerminateProcess "Gwxuxworker.exe"
    WSH.Echo "-------- Terminate Completed ---------"
    WSH.Echo
End Sub

Function CurrentUserIsAdmin()
    Dim objNetwork, strComputer, strUser, objUser, objGroup
    Set objNetwork = CreateObject("Wscript.Network")
    strComputer = objNetwork.ComputerName
    strUser = objNetwork.UserName

    CurrentUserIsAdmin = False

    Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
    For Each objUser in objGroup.Members
        If objUser.Name = strUser Then
            CurrentUserIsAdmin = True  
            Exit Function
        End If
    Next
End Function

' http://stackoverflow.com/questions/4765485/how-to-force-vbs-script-to-run-in-cscript-host
' http://stackoverflow.com/questions/4692542/force-a-vbs-to-run-using-cscript-instead-of-wscript
Sub ForceCScriptExecution(ByVal runAsAdmin)
    On Error Resume Next
    WScript.StdErr.Write(Chr(7))
    If Err.Number <> 0 Then
        Err.Clear
        On Error GoTo 0
        Dim WshShell, sh, Arg, Str
        Set WshShell = WScript.CreateObject("WScript.Shell")
        sh = WshShell.ExpandEnvironmentStrings("%SystemRoot%\System32\CScript.exe")
        If InStr(sh,"%") = 1 Then sh="CScript.exe"

        For Each Arg In WScript.Arguments
            If InStr( Arg, " " ) Then Arg = """" & Arg & """"
            Str = Str & " " & Arg
        Next
        
        If runAsAdmin Then
            Wscript.CreateObject("Shell.Application").ShellExecute _
             sh, "//NoLogo """ & _
            WScript.ScriptFullName & """ " & Str, "", "runas", 1
        Else
            WshShell.Run sh & " //NoLogo """ & _
                WScript.ScriptFullName & """ " & Str
        End If
        WScript.Quit()
    End If
End Sub

Function GetWindowsVersion()
    Dim strComputer, objWMIService
    Dim colOperatingSystem, objOperatingSystem
    strComputer = "."
    Set objWMIService = GetObject( _
        "winmgmts:{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\cimv2")
    Set colOperatingSystem = _
        objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
        
    Dim Version
    For Each objOperatingSystem in colOperatingSystem
        Version = objOperatingSystem.Version
    Next
    
    GetWindowsVersion = Version
End Function

Sub Pause(strPause)
     WScript.Echo (strPause)
     WScript.StdIn.Read(1)
End Sub

Function VBMain()
    VBMain = 0
    
    Dim strVersion, arrVersion
    strVersion = GetWindowsVersion()
    arrVersion = Split(strVersion, ".")
    ' https://msdn.microsoft.com/ru-ru/library/windows/desktop/ms724832(v=vs.85).aspx
    If CInt(arrVersion(0)) <> 6 Or _
        (CInt(arrVersion(0)) = 6 And _
         ( CInt(arrVersion(1)) <> 1 And _
           CInt(arrVersion(1)) <> 2 And _
           CInt(arrVersion(1)) <> 3 )) Then
      MsgBox "This Script Must Run under Windows 7/8/8.1"
      VBMain = 1
      Exit Function
    End If
    
    ForceCScriptExecution True

    WSH.Echo "Disable Windows 10 Upgrade Tool 1.0" & vbCrLf &_
              "Written By WangYe http://wangye.org/" & vbCrLf & vbCrLf
              
    If Not CurrentUserIsAdmin() Then
      WSH.Echo "**** Error: This Script Must Run under Administrators Account ****"
      Pause "Press any key to exit..."
      VBMain = 1
      Exit Function
    End If
    
    KillProcesses
    RemoveWinUpdates
    UpdateRegistry
    DeleteFiles
End Function

WSH.Quit(VBMain())

另存为 *.vbs 文件,直接双击即可(如果安全软件提示直接选择允许),这一段脚本其实还有一些小问题,比如隐藏更新的功能貌似一直无效,所以隐藏更新还需要手动操作,另外检查Windows更新时候等待的时间非常之长,需要有足够的耐心,所以总体上这段代码还是供大家参考吧。

第二部分,如何从已经升级Windows 10退回到旧系统

如果已经不小心升级,在30天内还可以通过以下方式进行补救,点击左下角开始标识(田字标志),点击 “设置” ,如下图所示:

Windows 10 设置

点击 “更新和安全” 选项,如下图所示:

Windows 10 更新和安全

选择“恢复”并在右边找到 “回退到Windows 7” ,点击“开始”即可完成回滚过程,如下图所示:

Windows 10回退到Windows 7

参考文档