关闭Windows基于虚拟化的安全性指北-全品牌通用方案

本文为受腾讯游戏安全ACE所扰用户常见的各种疑难杂症而诞生。

特别提醒:关闭虚拟化可能会降低系统安全性,会增加被恶意软件攻击的风险。建议仅在必要时进行,并确保安装可靠的安全软件来保护系统。关闭“基于虚拟化的安全性”主要是用以解决某些软件(如南方CASS、ENSP)等无法在虚拟化环境运行的问题,非必要不建议关闭!

使用dgreadiness工具关闭Windows虚拟化安全功能的完整流程

目录

  1. 背景介绍
  2. 工具准备
  3. 完整操作流程
  4. 注意事项
  5. 常见应用场景

背景介绍

Windows虚拟化安全功能概述

Windows虚拟化安全(Virtualization-Based Security,简称VBS)是一组基于硬件虚拟化技术的安全特性集合,利用CPU的虚拟化扩展能力(Intel VT-x/AMD-V)创建一个受保护的隔离环境,用于保护关键系统组件和敏感数据。

核心组件

1. 虚拟化安全(VBS)

  • VBS是整个虚拟化安全架构的基础设施
  • 利用Windows Hypervisor创建虚拟安全模式(VSM)
  • 在操作系统内核下方构建隔离的执行环境

2. Hypervisor强制代码完整性(HVCI)

  • 俗称:内存完整性(Memory Integrity)
  • 功能:将代码完整性检查隔离在VSM中执行
  • 作用:防止恶意代码修改内核内存,确保只有经过验证的可信代码才能在内核模式下执行
  • 防护目标:内核级漏洞利用、Rootkit、驱动程序攻击

3. 凭据保护(Credential Guard)

  • 基于VBS保护敏感凭据信息
  • 隔离本地安全机构(LSA)进程
  • 防护目标:凭据窃取攻击(如Pass-the-Hash、Pass-the-Ticket)

4. 核心隔离(Core Isolation)

  • Windows 11中引入的用户界面概念
  • 整合了内存完整性、内核隔离等功能
  • 用户可通过Windows安全中心界面进行管理

工作原理

┌─────────────────────────────────────────┐
│ Windows操作系统层 │
├─────────────────────────────────────────┤
│ Windows Hypervisor (VMM) │
│ - 创建虚拟安全模式(VSM) │
│ - 内存隔离与访问控制 │
├─────────────────────────────────────────┤
│ VSM内部安全组件: │
│ - HVCI(代码完整性检查) │
│ - Credential Guard(凭据保护) │
│ - 其他安全服务 │
├─────────────────────────────────────────┤
│ 硬件虚拟化层 │
│ - Intel VT-x / AMD-V │
│ - SLAT(二级地址转换) │
│ - TPM 2.0(可信平台模块) │
└─────────────────────────────────────────┘

需要关闭VBS功能的典型场景

1. 虚拟化软件兼容性问题

问题表现:

VMware Workstation unrecoverable error: (vcpu-2) 
Exception 0x80000003 (debug breakpoint) has occurred.



VirtualBox错误:
VT-x is disabled in the BIOS for all CPU modes
(VERR_VMX_MSR_ALL_VMX_DISABLED)

原因分析:

  • Windows VBS占用了CPU的硬件虚拟化功能
  • 第三方虚拟化软件(VMware、VirtualBox等)无法独占使用VT-x/AMD-V
  • 导致虚拟机性能严重下降(约40%性能损失)或无法启动

影响范围:

  • VMware Workstation Pro/Player
  • Oracle VirtualBox
  • QEMU/KVM(Windows主机)
  • Android模拟器(HAXM)
  • Docker Desktop(基于WSL2)

2. 驱动程序兼容性问题

常见症状:

# 驱动加载失败
事件查看器中显示错误:
Event ID: 3076
Code Integrity determined that a process (\Device\HarddiskVolume3\Windows\System32\drivers\incompatible_driver.sys) attempted to load non-Microsoft signed code that failed the HVCI policy check.

受影响驱动类型:

  • 老旧硬件驱动程序(未经过HVCI兼容性认证)
  • 自定义内核驱动(如某些游戏外设驱动)
  • 专业设备驱动(工业控制、测量仪器等)
  • 反作弊软件驱动(部分游戏反作弊系统)

3. 性能优化需求

性能影响:

场景 性能影响 说明
通用办公 0-5% 几乎无感知
CPU密集型任务 5-10% 编译、科学计算等
游戏性能 3-8% 取决于游戏类型
虚拟化场景 30-50% 与第三方虚拟化软件冲突
I/O密集型操作 5-15% 频繁的内存完整性检查

4. 特定应用要求

应用示例:

  • CASS11测绘软件(反调试机制与VBS冲突)
  • 某些数字取证工具
  • 逆向分析工具(需要直接访问底层硬件)
  • 性能基准测试软件

5. 企业环境管理需求

管理场景:

  • 统一的虚拟化平台部署
  • 兼容性测试环境
  • 开发调试环境
  • 临时安全策略调整

工具准备

dgreadiness工具介绍

基本信息

官方名称: Device Guard and Credential Guard hardware readiness tool
版本: 3.6
发布日期: 2024年7月15日
文件大小: 31.7 KB
文件格式: dgreadiness_v3.6.zip

工具类型: PowerShell脚本工具

核心功能

  1. 就绪性检查(Capability Check)

    • 检测硬件是否支持Device Guard/Credential Guard
    • 验证BIOS/UEFI配置是否正确
    • 检查驱动程序兼容性
  2. 状态查询(Status Check)

    • 查询VBS当前运行状态
    • 显示各安全组件启用情况
    • 生成详细的兼容性报告
  3. 启用/禁用功能(Enable/Disable)

    • 启用或禁用Device Guard
    • 启用或禁用Credential Guard
    • 启用或禁用HVCI(内存完整性)
  4. HLK测试支持

    • 检查设备是否通过Hardware Lab Kit测试
    • 为驱动程序开发者提供测试支持
  5. 策略集成

    • 支持自定义Code Integrity策略
    • 可与System Center Configuration Manager集成

支持的操作系统

操作系统 版本要求 支持状态
Windows 10 1607及以上 ✅ 完全支持
Windows 11 所有版本 ✅ 完全支持
Windows Server 2016 所有版本 ✅ 完全支持
Windows Server 2019 所有版本 ✅ 完全支持
Windows Server 2022 所有版本 ✅ 完全支持

工具获取方式

方法1:官方下载页(推荐)

下载步骤:

  1. 访问官方下载页面

    点击跳转: https://www.microsoft.com/en-us/download/details.aspx?id=53337

  2. 选择语言

    • 在页面顶部选择所需语言(如English)
    • 页面内容会动态更新为所选语言
  3. 下载文件

    • 点击”Download”按钮
    • 选择”dgreadiness_v3.6.zip”文件
  4. 保存文件

    • 建议保存到常用下载目录
    • 记住保存位置以便后续操作

方法2:命令行下载(高级用户)

使用PowerShell下载:

# 设置下载路径
$downloadPath = "$env:USERPROFILE\Downloads"
$downloadUrl = "https://download.microsoft.com/download/6/4/1/641C3FAF-2C49-45D6-8E8A-C8FD93B2F7C3/dgreadiness_v3.6.zip"
$destination = "$downloadPath\dgreadiness_v3.6.zip"

# 创建WebClient对象并下载
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($downloadUrl, $destination)

Write-Host "下载完成,文件保存在: $destination" -ForegroundColor Green

使用curl下载(Windows 10 1803+):

curl -L -o "$env:USERPROFILE\Downloads\dgreadiness_v3.6.zip" https://download.microsoft.com/download/6/4/1/641C3FAF-2C49-45D6-8E8A-C8FD93B2F7C3/dgreadiness_v3.6.zip

安装步骤

步骤1:解压文件

Windows资源管理器方式:

  1. 导航到下载目录(如:C:\Users\YourName\Downloads
  2. 右键点击dgreadiness_v3.6.zip
  3. 选择”全部提取(Extract All)”
  4. 选择目标目录(推荐:C:\Tools\dgreadiness_v3.6
  5. 点击”提取”完成解压

PowerShell解压方式:

# 定义源路径和目标路径
$sourcePath = "$env:USERPROFILE\Downloads\dgreadiness_v3.6.zip"
$destinationPath = "C:\Tools\dgreadiness_v3.6"

# 创建目标目录(如果不存在)
if (-not (Test-Path $destinationPath)) {
New-Item -ItemType Directory -Path $destinationPath -Force
}

# 解压文件
Expand-Archive -Path $sourcePath -DestinationPath $destinationPath -Force

Write-Host "解压完成,文件保存在: $destinationPath" -ForegroundColor Green

步骤2:验证文件完整性

解压后应包含以下文件:

dgreadiness_v3.6/
├── DG_Readiness_Tool_v3.6.ps1 # 主脚本文件
├── readme.txt # 使用说明
└── DGLogs/ # 日志目录(运行后生成)

文件验证命令:

# 查看文件列表
Get-ChildItem "C:\Tools\dgreadiness_v3.6" -Recurse

# 验证主脚本文件
$scriptPath = "C:\Tools\dgreadiness_v3.6\DG_Readiness_Tool_v3.6.ps1"
if (Test-Path $scriptPath) {
Write-Host "✓ 主脚本文件存在" -ForegroundColor Green
$fileInfo = Get-Item $scriptPath
Write-Host " 文件大小: $($fileInfo.Length) 字节" -ForegroundColor Gray
Write-Host " 修改时间: $($fileInfo.LastWriteTime)" -ForegroundColor Gray
} else {
Write-Host "✗ 主脚本文件不存在" -ForegroundColor Red
}

步骤3:阅读使用说明

查看readme.txt:

# 在记事本中打开
notepad "C:\Tools\dgreadiness_v3.6\readme.txt"

# 或在PowerShell中查看内容
Get-Content "C:\Tools\dgreadiness_v3.6\readme.txt"

readme.txt主要内容摘要:

================================================================================
Device Guard and Credential Guard Hardware Readiness Tool
Version 3.6
================================================================================

USAGE:
------
DG_Readiness.ps1 -[Enable/Disable/Capable/Ready] -[DG/CG/HVCI/HLK]
-Path <ConfigCI policy> -AutoReboot

PARAMETERS:
-----------
-Enable : Enable the specified feature
-Disable : Disable the specified feature
-Capable : Check if the device is capable of running the feature
-Ready : Check if the device is ready to run the feature
-DG : Device Guard
-CG : Credential Guard
-HVCI : Hypervisor-Enforced Code Integrity
-HLK : Hardware Lab Kit tests
-Path : Path to ConfigCI policy file
-AutoReboot: Automatically reboot after configuration changes

EXAMPLES:
---------
# Check if device can run Device Guard
.\DG_Readiness_Tool_v3.6.ps1 -Capable -DG

# Enable HVCI
.\DG_Readiness_Tool_v3.6.ps1 -Enable -HVCI

# Disable Credential Guard
.\DG_Readiness_Tool_v3.6.ps1 -Disable -CG

# Check status of all features
.\DG_Readiness_Tool_v3.6.ps1 -Ready -DG -CG -HVCI

REQUIREMENTS:
-------------
- Windows 10 version 1607 or later
- Windows Server 2016 or later
- Administrator privileges
- PowerShell execution policy must allow script execution

工具基本功能说明

功能1:就绪性检查

检查设备是否支持Device Guard:

.\DG_Readiness_Tool_v3.6.ps1 -Capable -DG

检查设备是否支持Credential Guard:

.\DG_Readiness_Tool_v3.6.ps1 -Capable -CG

检查设备是否支持HVCI:

.\DG_Readiness_Tool_v3.6.ps1 -Capable -HVCI

输出示例:

Device Guard Capability Check Results:

Hardware Requirements:
=======================
✓ 64-bit processor: Supported
✓ Virtualization extensions: Supported
✓ Second Level Address Translation (SLAT): Supported
✓ UEFI 2.3.1 or later: Supported
✓ Secure Boot: Supported

Software Requirements:
=======================
✓ Windows 10/11: Compatible
✓ TPM 2.0: Available

Overall Status: CAPABLE

功能2:状态查询

查询Device Guard状态:

.\DG_Readiness_Tool_v3.6.ps1 -Ready -DG

查询所有功能状态:

.\DG_Readiness_Tool_v3.6.ps1 -Ready -DG -CG -HVCI

输出示例:

Current Status Report:

Virtualization-Based Security: RUNNING
- Base Virtualization Support: ENABLED
- Secure Boot: ENABLED
- DMA Protection: ENABLED

Device Guard: ENABLED
- Configurable Code Integrity: ENABLED
- VSM Protected Code Integrity: ENABLED

Credential Guard: ENABLED
- LSA Isolation: RUNNING

HVCI (Memory Integrity): ENABLED
- Hypervisor Enforced Code Integrity: RUNNING

功能3:启用功能

启用Device Guard:

.\DG_Readiness_Tool_v3.6.ps1 -Enable -DG -AutoReboot

启用Credential Guard:

.\DG_Readiness_Tool_v3.6.ps1 -Enable -CG -AutoReboot

启用HVCI(内存完整性):

.\DG_Readiness_Tool_v3.6.ps1 -Enable -HVCI -AutoReboot

功能4:禁用功能

禁用Device Guard:

.\DG_Readiness_Tool_v3.6.ps1 -Disable -DG -AutoReboot

禁用Credential Guard:

.\DG_Readiness_Tool_v3.6.ps1 -Disable -CG -AutoReboot

禁用HVCI(内存完整性):

.\DG_Readiness_Tool_v3.6.ps1 -Disable -HVCI -AutoReboot

功能5:高级用法

使用自定义策略启用:

.\DG_Readiness_Tool_v3.6.ps1 -Enable -DG -Path "C:\Policies\MyCIPolicy.p7b"

检查HLK测试就绪性:

.\DG_Readiness_Tool_v3.6.ps1 -Capable -HLK

批量查询多台计算机(需要远程管理权限):

$computers = @("PC01", "PC02", "PC03")
foreach ($computer in $computers) {
Write-Host "Checking $computer..." -ForegroundColor Cyan
Invoke-Command -ComputerName $computer -ScriptBlock {
& "C:\Tools\dgreadiness_v3.6\DG_Readiness_Tool_v3.6.ps1" -Ready -HVCI
}
}

完整操作流程

前置准备

步骤1:确认管理员权限

检查当前权限:

# 方法1:检查当前用户是否是管理员
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

if ($isAdmin) {
Write-Host "✓ 当前具有管理员权限" -ForegroundColor Green
} else {
Write-Host "✗ 需要管理员权限,请以管理员身份重新运行PowerShell" -ForegroundColor Red
Write-Host "提示:右键点击PowerShell,选择'以管理员身份运行'" -ForegroundColor Yellow
exit
}

方法2:使用UAC提示(如果非管理员):

# 自动请求管理员权限
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
exit
}

步骤2:检查PowerShell执行策略

查看当前执行策略:

Get-ExecutionPolicy -List

输出示例:

    MachinePolicy
UserPolicy
Process
CurrentUser RemoteSigned
LocalMachine Restricted

临时修改执行策略(仅当前会话):

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
Write-Host "✓ 执行策略已设置为Bypass(仅当前会话)" -ForegroundColor Green

永久修改执行策略(不推荐):

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force
Write-Host "✓ 执行策略已设置为RemoteSigned" -ForegroundColor Green

步骤3:备份系统配置

创建系统还原点:

# 检查是否启用系统保护
$systemProtection = Get-ComputerRestorePoint
if ($systemProtection) {
Write-Host "✓ 系统保护已启用" -ForegroundColor Green
} else {
Write-Host "✗ 系统保护未启用,跳过还原点创建" -ForegroundColor Yellow
}

# 创建还原点
$description = "Before disabling VBS with dgreadiness"
try {
Checkpoint-Computer -Description $description -RestorePointType "MODIFY_SETTINGS"
Write-Host "✓ 系统还原点创建成功: $description" -ForegroundColor Green
} catch {
Write-Host "✗ 创建还原点失败: $_" -ForegroundColor Red
}

导出当前注册表配置:

# 创建备份目录
$backupDir = "C:\DGReadiness_Backup_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
New-Item -ItemType Directory -Path $backupDir -Force | Out-Null

# 导出Device Guard相关注册表项
$regPaths = @(
"HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard",
"HKLM:\SYSTEM\CurrentControlSet\Control\Lsa",
"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce"
)

foreach ($path in $regPaths) {
$backupFile = "$backupDir\$($path.Replace('\', '_').Replace(':', '')).reg"
try {
reg export $path $backupFile /y
Write-Host "✓ 已备份: $path" -ForegroundColor Green
} catch {
Write-Host "✗ 备份失败: $path" -ForegroundColor Red
}
}

Write-Host "注册表备份完成,保存在: $backupDir" -ForegroundColor Cyan

导出BCD配置:

$bcdBackupFile = "$backupDir\BCD_Backup.txt"
try {
bcdedit /enum all > $bcdBackupFile
Write-Host "✓ BCD配置已备份: $bcdBackupFile" -ForegroundColor Green
} catch {
Write-Host "✗ BCD备份失败: $_" -ForegroundColor Red
}

步骤4:查看当前VBS状态

使用系统信息工具(msinfo32):

# 启动系统信息工具
Start-Process msinfo32

# 或使用PowerShell查询
Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard |
Select-Object @{N="基于虚拟化的安全性";E={$_.VirtualizationBasedSecurityStatus}},
@{N="安全服务运行中";E={$_.SecurityServicesConfigured}},
@{N="HVCI状态";E={$_.SecurityServicesRunning}} |
Format-List

使用PowerShell详细查询:

# 查询VBS状态
$vbsStatus = Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard

Write-Host "当前VBS状态报告:" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray
Write-Host "基于虚拟化的安全性状态: $($vbsStatus.VirtualizationBasedSecurityStatus)" -ForegroundColor White
Write-Host "已配置的安全服务: $($vbsStatus.SecurityServicesConfigured)" -ForegroundColor White
Write-Host "正在运行的安全服务: $($vbsStatus.SecurityServicesRunning)" -ForegroundColor White

# 检查HVCI是否启用
if ($vbsStatus.SecurityServicesRunning -band 1) {
Write-Host "HVCI(内存完整性): 启用" -ForegroundColor Green
} else {
Write-Host "HVCI(内存完整性): 禁用" -ForegroundColor Red
}

# 检查Credential Guard是否启用
if ($vbsStatus.SecurityServicesRunning -band 2) {
Write-Host "Credential Guard: 启用" -ForegroundColor Green
} else {
Write-Host "Credential Guard: 禁用" -ForegroundColor Red
}

使用Windows安全中心查看:

# 打开Windows安全中心 - 核心隔离页面
Start-Process "ms-settings:windowssecurity-coreisolation"

Write-Host "请检查'核心隔离'页面中的'内存完整性'设置" -ForegroundColor Yellow

工具脚本使用详解

步骤5:导航到工具目录

方法1:使用cd命令:

# 切换到工具目录
Set-Location "C:\Tools\dgreadiness_v3.6"

# 验证当前位置
Write-Host "当前工作目录: $(Get-Location)" -ForegroundColor Cyan

方法2:使用变量路径:

# 定义工具路径
$dgToolPath = "C:\Tools\dgreadiness_v3.6"

# 切换目录
Set-Location $dgToolPath

# 检查脚本文件是否存在
$scriptPath = Join-Path $dgToolPath "DG_Readiness_Tool_v3.6.ps1"
if (Test-Path $scriptPath) {
Write-Host "✓ 工具脚本文件存在" -ForegroundColor Green
} else {
Write-Host "✗ 工具脚本文件不存在,请检查路径" -ForegroundColor Red
exit
}

步骤6:查看帮助信息

获取脚本帮助:

# 查看帮助信息
Get-Help .\DG_Readiness_Tool_v3.6.ps1 -Full

# 或查看参数说明
Get-Help .\DG_Readiness_Tool_v3.6.ps1 -Parameter *

输出示例:

NAME
DG_Readiness_Tool_v3.6.ps1

SYNOPSIS
Device Guard and Credential Guard hardware readiness tool

SYNTAX
.\DG_Readiness_Tool_v3.6.ps1 [-Enable] [-Disable] [-Capable] [-Ready]
[-DG] [-CG] [-HVCI] [-HLK] [-Path] [-AutoReboot] [<CommonParameters>]

PARAMETERS
-Enable
Enable the specified feature

-Disable
Disable the specified feature

-Capable
Check if device is capable

-Ready
Check if device is ready

-DG
Device Guard

-CG
Credential Guard

-HVCI
Hypervisor-Enforced Code Integrity

-HLK
Hardware Lab Kit tests

-Path
ConfigCI policy path

-AutoReboot
Automatically reboot

步骤7:运行就绪性检查

检查HVCI就绪性:

Write-Host "开始HVCI就绪性检查..." -ForegroundColor Cyan
.\DG_Readiness_Tool_v3.6.ps1 -Capable -HVCI

检查所有功能就绪性:

Write-Host "开始全面就绪性检查..." -ForegroundColor Cyan
.\DG_Readiness_Tool_v3.6.ps1 -Capable -DG -CG -HVCI -HLK

分析检查结果:

检查完成后,工具会生成详细报告。主要关注以下信息:

=== HVCI Capability Check Results ===

Hardware Requirements:
[✓] 64-bit processor
[✓] Virtualization extensions (VT-x/AMD-V)
[✓] Second Level Address Translation (SLAT)
[✓] UEFI 2.3.1 or later
[✓] Secure Boot
[?] TPM 2.0 (Recommended but not required)

Driver Compatibility:
[!] Found 3 potentially incompatible drivers:
- C:\Windows\System32\drivers\old_driver.sys (Version 1.0.0.1)
- C:\Windows\System32\drivers\custom_device.sys (Version 2.3.0.0)
- C:\Windows\System32\drivers\legacy_hardware.sys (Version 2019.01.01)

Overall Status: CAPABLE WITH WARNINGS

如果显示”不兼容驱动”,需要先处理:

# 使用PowerShell查找不兼容驱动
Get-CimInstance -ClassName Win32_PnPSignedDriver |
Where-Object { $_.DriverVersion -lt "2.0.0.0" } |
Select-Object DeviceName, DriverVersion, DriverDate, InfName |
Format-Table -AutoSize

步骤8:禁用VBS/HVCI功能

方法1:禁用整个VBS(推荐)

Write-Host "开始禁用虚拟化安全(VBS)..." -ForegroundColor Cyan
Write-Host "警告:此操作将禁用以下功能:" -ForegroundColor Yellow
Write-Host " - Device Guard" -ForegroundColor Gray
Write-Host " - Credential Guard" -ForegroundColor Gray
Write-Host " - HVCI(内存完整性)" -ForegroundColor Gray
Write-Host ""

# 请求确认
$confirmation = Read-Host "是否继续?(Y/N)"
if ($confirmation -ne 'Y' -and $confirmation -ne 'y') {
Write-Host "操作已取消" -ForegroundColor Yellow
exit
}

# 执行禁用命令
Write-Host "执行禁用命令..." -ForegroundColor Cyan
.\DG_Readiness_Tool_v3.6.ps1 -Disable -AutoReboot

Write-Host "命令执行完成,系统将自动重启" -ForegroundColor Green

方法2:仅禁用HVCI(内存完整性)

Write-Host "开始禁用HVCI(内存完整性)..." -ForegroundColor Cyan
Write-Host "注意:Credential Guard等其他VBS功能将保持启用状态" -ForegroundColor Yellow
Write-Host ""

# 请求确认
$confirmation = Read-Host "是否继续?(Y/N)"
if ($confirmation -ne 'Y' -and $confirmation -ne 'y') {
Write-Host "操作已取消" -ForegroundColor Yellow
exit
}

# 执行禁用命令
Write-Host "执行禁用命令..." -ForegroundColor Cyan
.\DG_Readiness_Tool_v3.6.ps1 -Disable -HVCI -AutoReboot

Write-Host "命令执行完成,系统将自动重启" -ForegroundColor Green

方法3:分步禁用(高级用户)

# 步骤1:禁用Credential Guard
Write-Host "[1/3] 禁用Credential Guard..." -ForegroundColor Cyan
.\DG_Readiness_Tool_v3.6.ps1 -Disable -CG

# 步骤2:禁用HVCI
Write-Host "[2/3] 禁用HVCI..." -ForegroundColor Cyan
.\DG_Readiness_Tool_v3.6.ps1 -Disable -HVCI

# 步骤3:禁用Device Guard
Write-Host "[3/3] 禁用Device Guard..." -ForegroundColor Cyan
.\DG_Readiness_Tool_v3.6.ps1 -Disable -DG -AutoReboot

Write-Host "所有步骤完成,系统将自动重启" -ForegroundColor Green

步骤9:重启系统

自动重启(使用-AutoReboot参数):

# 如果使用了-AutoReboot参数,系统会自动重启
# 无需手动操作

手动重启:

# 查看当前时间,给用户准备时间
Write-Host "当前时间: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" -ForegroundColor Cyan
Write-Host "系统将在30秒后重启,请保存所有工作..." -ForegroundColor Yellow

# 30秒倒计时
for ($i = 30; $i -gt 0; $i--) {
Write-Host "`r重启倒计时: $i 秒" -NoNewline
Start-Sleep -Seconds 1
}

Write-Host "`n正在重启系统..." -ForegroundColor Green
Restart-Computer -Force

带延迟的智能重启:

# 检查是否有重要进程运行
$importantProcesses = @("excel", "winword", "powerpnt", "notepad", "code")
$runningProcesses = Get-Process | Where-Object { $importantProcesses -contains $_.ProcessName }

if ($runningProcesses) {
Write-Host "检测到以下程序正在运行:" -ForegroundColor Yellow
$runningProcesses | Select-Object ProcessName, MainWindowTitle | Format-Table

$response = Read-Host "是否继续重启?(Y/N)"
if ($response -ne 'Y' -and $response -ne 'y') {
Write-Host "重启已取消,请手动关闭程序后重新运行脚本" -ForegroundColor Yellow
exit
}
}

# 执行重启
Write-Host "正在重启系统..." -ForegroundColor Green
Restart-Computer -Force

处理”不安全”提示

问题1:PowerShell执行策略限制

错误信息:

.\DG_Readiness_Tool_v3.6.ps1 : 无法加载文件 DG_Readiness_Tool_v3.6.ps1,因为在此系统上禁止运行脚本。

解决方案:

# 查看当前执行策略
Write-Host "当前执行策略:" -ForegroundColor Cyan
Get-ExecutionPolicy -List | Format-Table -AutoSize

# 临时设置为Bypass(仅当前会话)
Write-Host "`n设置执行策略为Bypass(当前会话)..." -ForegroundColor Yellow
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force

# 验证设置
Write-Host "当前会话执行策略: $(Get-ExecutionPolicy -Scope Process)" -ForegroundColor Green

# 现在可以运行脚本了
Write-Host "`n现在可以运行脚本了" -ForegroundColor Green

永久解决方案(谨慎使用):

# 设置为RemoteSigned(允许本地脚本和已签名的远程脚本)
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force

# 或设置为Unrestricted(不推荐,安全风险高)
# Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force

问题2:UAC权限不足

错误信息:

访问被拒绝。您需要管理员权限才能运行此脚本。

解决方案1:自动提升权限

# 创建自动提升脚本
$selfElevateScript = @'
# 检查是否具有管理员权限
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
$isAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

if (-not $isAdmin) {
# 重新启动脚本,使用管理员权限
$arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""
Start-Process powershell.exe -Verb RunAs -ArgumentList $arguments
exit
}

# 这里放置实际的脚本代码
Write-Host "✓ 已获得管理员权限" -ForegroundColor Green
'@

# 保存为临时文件
$tempScript = "$env:TEMP\SelfElevate.ps1"
$selfElevateScript | Out-File -FilePath $tempScript -Encoding UTF8

# 执行脚本
& $tempScript

解决方案2:手动以管理员身份运行

  1. 关闭当前的PowerShell窗口
  2. Win + X
  3. 选择”Windows PowerShell (管理员)”或”终端 (管理员)”
  4. 导航到工具目录并运行脚本

问题3:Windows Defender拦截

错误信息:

Windows Defender已阻止此应用,因为它检测到潜在的不安全行为。

解决方案:

# 方法1:临时关闭实时保护(需要管理员权限)
# 打开Windows安全中心
Start-Process "ms-settings:windowssecurity"

# 或使用PowerShell添加排除项
$scriptPath = "C:\Tools\dgreadiness_v3.6"
Add-MpPreference -ExclusionPath $scriptPath
Write-Host "已将工具目录添加到Windows Defender排除项" -ForegroundColor Green

# 方法2:使用Set-MpPreference(需要管理员权限)
Set-MpPreference -DisableRealtimeMonitoring $true
Write-Host "已临时关闭实时保护" -ForegroundColor Yellow
Write-Host "警告:请在操作完成后重新启用实时保护" -ForegroundColor Red

# 操作完成后重新启用
# Set-MpPreference -DisableRealtimeMonitoring $false

通过GUI添加排除项:

  1. 打开Windows安全中心
  2. 点击”病毒和威胁防护”
  3. 点击”病毒和威胁防护设置”下的”管理设置”
  4. 向下滚动到”排除项”
  5. 点击”添加或删除排除项”
  6. 添加C:\Tools\dgreadiness_v3.6目录

问题4:组策略限制

错误信息:

此操作已被组策略阻止。

解决方案:

# 检查相关组策略设置
$policyPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DeviceGuard"
if (Test-Path $policyPath) {
Write-Host "检测到Device Guard组策略设置:" -ForegroundColor Yellow
Get-ItemProperty -Path $policyPath | Format-List
}

# 检查LsaCfgFlags设置
$lsaPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa"
$lsaFlags = (Get-ItemProperty -Path $lsaPath -ErrorAction SilentlyContinue).LsaCfgFlags
if ($lsaFlags) {
Write-Host "LSA隔离配置: $lsaFlags" -ForegroundColor Yellow
Write-Host " 0 = 未启用" -ForegroundColor Gray
Write-Host " 1 = 启用并使用UEFI锁" -ForegroundColor Gray
Write-Host " 2 = 启用但不使用UEFI锁" -ForegroundColor Gray
}

# 临时禁用组策略限制(需要管理员权限)
if (Test-Path $policyPath) {
Write-Host "`n尝试临时禁用Device Guard组策略..." -ForegroundColor Cyan

# 备份当前设置
$backupPath = "$backupDir\GroupPolicy_Backup.reg"
reg export "HKLM\SOFTWARE\Policies\Microsoft\Windows\DeviceGuard" $backupPath /y

# 禁用Device Guard
Set-ItemProperty -Path $policyPath -Name "EnableDeviceGuard" -Value 0 -ErrorAction SilentlyContinue
Set-ItemProperty -Path $policyPath -Name "ConfigureSystemGuardLaunch" -Value 0 -ErrorAction SilentlyContinue

Write-Host "组策略设置已临时修改" -ForegroundColor Green
}

通过组策略编辑器修改:

  1. Win + R,输入 gpedit.msc
  2. 导航到:计算机配置 → 管理模板 → 系统 → Device Guard
  3. 找到”启用基于虚拟化的安全性”
  4. 设置为”已禁用”
  5. 点击”应用”和”确定”
  6. 运行 gpupdate /force 更新组策略

问题5:SecConfig.efi启动菜单

问题描述:
重启后出现蓝色启动菜单,提示是否禁用Credential Guard/VBS。

解决方案:

# 正确处理启动菜单
Write-Host "系统重启后会出现启动选择菜单:" -ForegroundColor Cyan
Write-Host "====================================" -ForegroundColor Gray
Write-Host "Credential Guard退出工具" -ForegroundColor White
Write-Host "" -ForegroundColor White
Write-Host "是否要禁用Credential Guard?" -ForegroundColor Yellow
Write-Host "禁用此功能可能会允许恶意软件读取所有登录Windows" -ForegroundColor Yellow
Write-Host "用户的密码和其他凭据。在禁用保护之前,请与您的" -ForegroundColor Yellow
Write-Host "管理员联系以采取适合您组织的操作。" -ForegroundColor Yellow
Write-Host "" -ForegroundColor White
Write-Host "按Windows键或F3禁用Credential Guard,ESC跳过此步骤。" -ForegroundColor Green
Write-Host "====================================" -ForegroundColor Gray
Write-Host ""

Write-Host "操作步骤:" -ForegroundColor Cyan
Write-Host "1. 按 F3 或 Windows键 选择禁用" -ForegroundColor White
Write-Host "2. 等待系统完成配置" -ForegroundColor White
Write-Host "3. 系统将再次重启并进入Windows" -ForegroundColor White
Write-Host ""

Write-Host "如果看到'基于虚拟化的安全性退出工具':" -ForegroundColor Cyan
Write-Host "1. 同样按 F3 或 Windows键 选择禁用" -ForegroundColor White
Write-Host "2. 按任意键继续" -ForegroundColor White
Write-Host "3. 系统将完成禁用操作并重启" -ForegroundColor White

自动处理SecConfig.efi(高级方法):

# 检查EFI系统分区
Write-Host "检查EFI系统分区..." -ForegroundColor Cyan

# 临时挂载ESP分区
$espDrive = "X:"
mountvol $espDrive /s

if (Test-Path "${espDrive}\EFI\Microsoft\Boot") {
Write-Host "✓ EFI分区已挂载到 $espDrive" -ForegroundColor Green

# 检查SecConfig.efi是否存在
$secConfigPath = "${espDrive}\EFI\Microsoft\Boot\SecConfig.efi"
if (Test-Path $secConfigPath) {
Write-Host "✓ SecConfig.efi 存在" -ForegroundColor Green

# 创建启动项
$guid = "{0cb3b571-2f2e-4343-a879-d86a476d7215}"
bcdedit /create $guid /d "Disable VBS Tool" /application osloader
bcdedit /set $guid path "\EFI\Microsoft\Boot\SecConfig.efi"
bcdedit /set $guid device partition=$espDrive
bcdedit /set $guid loadoptions DISABLE-VBS
bcdedit /set {bootmgr} bootsequence $guid

Write-Host "✓ 已创建VBS禁用启动项" -ForegroundColor Green
} else {
Write-Host "✗ SecConfig.efi 不存在" -ForegroundColor Red
}

# 卸载ESP分区
mountvol $espDrive /d
Write-Host "✓ EFI分区已卸载" -ForegroundColor Green
} else {
Write-Host "✗ 无法挂载EFI分区" -ForegroundColor Red
}

验证操作结果

步骤10:验证VBS是否已禁用

方法1:使用系统信息工具

# 启动系统信息
Start-Process msinfo32

Write-Host "在系统信息窗口中查找以下内容:" -ForegroundColor Cyan
Write-Host "1. 滚动到底部" -ForegroundColor White
Write-Host "2. 查找'基于虚拟化的安全性'项目" -ForegroundColor White
Write-Host "3. 确认状态为'未运行'(Not Running)" -ForegroundColor Green

方法2:使用PowerShell查询

Write-Host "VBS状态验证结果:" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray

# 获取Device Guard状态
$dgStatus = Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard

# 基于虚拟化的安全性
$vbsStatus = $dgStatus.VirtualizationBasedSecurityStatus
Write-Host "基于虚拟化的安全性: " -NoNewline
if ($vbsStatus -eq 0) {
Write-Host "未运行 ✓" -ForegroundColor Green
} else {
Write-Host "正在运行 ✗" -ForegroundColor Red
}

# 安全服务配置
$servicesConfigured = $dgStatus.SecurityServicesConfigured
Write-Host "已配置的安全服务: $servicesConfigured" -ForegroundColor White

# 安全服务运行
$servicesRunning = $dgStatus.SecurityServicesRunning
Write-Host "正在运行的安全服务: $servicesRunning" -ForegroundColor White

# 详细服务状态
Write-Host "`n详细服务状态:" -ForegroundColor Cyan
Write-Host "--------------------------------" -ForegroundColor Gray

# HVCI状态
if ($servicesRunning -band 1) {
Write-Host "HVCI(内存完整性): 启用 ✗" -ForegroundColor Red
} else {
Write-Host "HVCI(内存完整性): 禁用 ✓" -ForegroundColor Green
}

# Credential Guard状态
if ($servicesRunning -band 2) {
Write-Host "Credential Guard: 启用 ✗" -ForegroundColor Red
} else {
Write-Host "Credential Guard: 禁用 ✓" -ForegroundColor Green
}

# 写入保护状态
if ($dgStatus.Locked -eq 1) {
Write-Host "写入保护: 启用 ✗" -ForegroundColor Red
} else {
Write-Host "写入保护: 禁用 ✓" -ForegroundColor Green
}

方法3:使用Windows安全中心

# 打开核心隔离设置
Start-Process "ms-settings:windowssecurity-coreisolation"

Write-Host "在核心隔离页面中检查:" -ForegroundColor Cyan
Write-Host "1. 点击'核心隔离详细信息'" -ForegroundColor White
Write-Host "2. 确认'内存完整性'开关为'关闭'" -ForegroundColor Green
Write-Host "3. 如果显示'需要重启',请点击'立即重启'" -ForegroundColor Yellow

方法4:使用bcdedit命令

Write-Host "BCD启动配置验证:" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray

# 查看hypervisor启动类型
$hypervisorType = bcdedit /enum | Select-String "hypervisorlaunchtype"
Write-Host "Hypervisor启动类型: " -NoNewline
if ($hypervisorType -match "Off") {
Write-Host "关闭 ✓" -ForegroundColor Green
} else {
Write-Host "开启 ✗" -ForegroundColor Red
}

# 查看VSM启动类型
$vsmType = bcdedit /enum | Select-String "vsmlaunchtype"
Write-Host "VSM启动类型: " -NoNewline
if ($vsmType -match "Off") {
Write-Host "关闭 ✓" -ForegroundColor Green
} else {
Write-Host "开启 ✗" -ForegroundColor Red
}

步骤11:验证虚拟化功能释放

检查VT-x/AMD-V是否可用:

Write-Host "虚拟化功能验证:" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray

# 方法1:使用系统信息
$systemInfo = systeminfo
if ($systemInfo -match "Hyper-V Requirements:.*A hypervisor has been detected") {
Write-Host "Hyper-V Hypervisor: 检测到 ✗" -ForegroundColor Red
Write-Host "说明:VBS可能未完全禁用" -ForegroundColor Yellow
} else {
Write-Host "Hyper-V Hypervisor: 未检测到 ✓" -ForegroundColor Green
Write-Host "说明:虚拟化功能已释放" -ForegroundColor Green
}

# 方法2:检查WMI
$hypervisor = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object HypervisorPresent
Write-Host "HypervisorPresent: $($hypervisor.HypervisorPresent)" -ForegroundColor White

# 方法3:使用CoreInfo工具(如果已安装)
$coreInfoPath = "C:\Tools\CoreInfo.exe"
if (Test-Path $coreInfoPath) {
Write-Host "`n运行CoreInfo工具..." -ForegroundColor Cyan
& $coreInfoPath
}

使用第三方工具验证:

# 检查是否安装了Intel Processor Identification Utility
$intelUtil = Get-ChildItem -Path "C:\Program Files", "C:\Program Files (x86)" -Recurse -Filter "IntelProcessorIdentificationUtility.exe" -ErrorAction SilentlyContinue

if ($intelUtil) {
Write-Host "找到Intel处理器识别工具" -ForegroundColor Green
Write-Host "路径: $($intelUtil.FullName)" -ForegroundColor Gray

$response = Read-Host "是否启动工具查看虚拟化支持?(Y/N)"
if ($response -eq 'Y' -or $response -eq 'y') {
Start-Process $intelUtil.FullName
}
}

步骤12:生成验证报告

# 创建验证报告
$reportPath = "C:\DGReadiness_Verification_$(Get-Date -Format 'yyyyMMdd_HHmmss').txt"
$reportContent = @()
$reportContent += "dgreadiness工具禁用VBS操作验证报告"
$reportContent += "=" * 50
$reportContent += "生成时间: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
$reportContent += ""

# 添加系统信息
$reportContent += "系统信息:"
$reportContent += "-" * 30
$computerInfo = Get-CimInstance -ClassName Win32_ComputerSystem
$reportContent += "计算机名: $($computerInfo.Name)"
$reportContent += "操作系统: $((Get-CimInstance Win32_OperatingSystem).Caption)"
$reportContent += "版本: $((Get-CimInstance Win32_OperatingSystem).Version)"
$reportContent += ""

# 添加VBS状态
$reportContent += "VBS状态:"
$reportContent += "-" * 30
$dgStatus = Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard
$reportContent += "基于虚拟化的安全性: $($dgStatus.VirtualizationBasedSecurityStatus)"
$reportContent += "已配置的安全服务: $($dgStatus.SecurityServicesConfigured)"
$reportContent += "正在运行的安全服务: $($dgStatus.SecurityServicesRunning)"
$reportContent += "HVCI状态: $(if ($dgStatus.SecurityServicesRunning -band 1) { '启用' } else { '禁用' })"
$reportContent += "Credential Guard状态: $(if ($dgStatus.SecurityServicesRunning -band 2) { '启用' } else { '禁用' })"
$reportContent += ""

# 添加BCD配置
$reportContent += "BCD配置:"
$reportContent += "-" * 30
$hypervisorType = bcdedit /enum | Select-String "hypervisorlaunchtype"
$vsmType = bcdedit /enum | Select-String "vsmlaunchtype"
$reportContent += $hypervisorType.Line
$reportContent += $vsmType.Line
$reportContent += ""

# 添加总结
$reportContent += "操作总结:"
$reportContent += "-" * 30
if ($dgStatus.VirtualizationBasedSecurityStatus -eq 0 -and
$dgStatus.SecurityServicesRunning -eq 0) {
$reportContent += "✓ VBS已成功禁用"
$reportContent += "✓ 所有安全服务已停止"
$reportContent += "✓ 虚拟化功能已释放"
} else {
$reportContent += "✗ VBS可能未完全禁用"
$reportContent += "✗ 请检查日志文件或重新运行工具"
}

# 保存报告
$reportContent | Out-File -FilePath $reportPath -Encoding UTF8

Write-Host "验证报告已生成: $reportPath" -ForegroundColor Green
Write-Host "报告内容:" -ForegroundColor Cyan
Get-Content $reportPath

步骤13:测试虚拟化软件

测试VMware Workstation:

# 检查VMware是否安装
$vmwarePath = "${env:ProgramFiles(x86)}\VMware\VMware Workstation\vmware.exe"
if (Test-Path $vmwarePath) {
Write-Host "检测到VMware Workstation" -ForegroundColor Green

$response = Read-Host "是否启动VMware进行测试?(Y/N)"
if ($response -eq 'Y' -or $response -eq 'y') {
Start-Process $vmwarePath

Write-Host "VMware已启动" -ForegroundColor Green
Write-Host "请尝试启动虚拟机,查看是否正常工作" -ForegroundColor Yellow
Write-Host "如果虚拟机可以正常启动,说明VBS已成功禁用" -ForegroundColor Green
}
} else {
Write-Host "未检测到VMware Workstation" -ForegroundColor Gray
}

测试VirtualBox:

# 检查VirtualBox是否安装
$virtualBoxPath = "${env:ProgramFiles}\Oracle\VirtualBox\VirtualBox.exe"
if (Test-Path $virtualBoxPath) {
Write-Host "检测到VirtualBox" -ForegroundColor Green

$response = Read-Host "是否启动VirtualBox进行测试?(Y/N)"
if ($response -eq 'Y' -or $response -eq 'y') {
Start-Process $virtualBoxPath

Write-Host "VirtualBox已启动" -ForegroundColor Green
Write-Host "请尝试启动虚拟机,查看是否正常工作" -ForegroundColor Yellow
Write-Host "如果虚拟机可以正常启动,说明VBS已成功禁用" -ForegroundColor Green
}
} else {
Write-Host "未检测到VirtualBox" -ForegroundColor Gray
}

通用虚拟化测试脚本:

# 通用虚拟化功能测试
Write-Host "虚拟化功能测试:" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray

# 测试1:检查Hyper-V服务
Write-Host "`n[测试1] Hyper-V服务状态" -ForegroundColor Cyan
$hyperVServices = @("hvboot", "HvHost", "vmickvpexchange", "vmicguestinterface",
"vmicshutdown", "vmicheartbeat", "vmicvmsession", "vmicrdv")
foreach ($service in $hyperVServices) {
$svc = Get-Service -Name $service -ErrorAction SilentlyContinue
if ($svc) {
Write-Host "$service : $($svc.Status)" -ForegroundColor White
}
}

# 测试2:检查虚拟机监控程序
Write-Host "`n[测试2] 虚拟机监控程序状态" -ForegroundColor Cyan
$hypervisor = Get-CimInstance -ClassName Win32_ComputerSystem
Write-Host "HypervisorPresent: $($hypervisor.HypervisorPresent)" -ForegroundColor $(if ($hypervisor.HypervisorPresent) { "Red" } else { "Green" })

# 测试3:检查CPU虚拟化支持
Write-Host "`n[测试3] CPU虚拟化支持" -ForegroundColor Cyan
$cpu = Get-CimInstance -ClassName Win32_Processor
Write-Host "处理器: $($cpu.Name)" -ForegroundColor White

# 检查虚拟化功能
$virtualizationEnabled = $false
if ($cpu.SecondLevelAddressTranslationExtensions) {
Write-Host "SLAT(二级地址转换): 支持" -ForegroundColor Green
$virtualizationEnabled = $true
} else {
Write-Host "SLAT(二级地址转换): 不支持" -ForegroundColor Red
}

if ($cpu.VirtualizationFirmwareEnabled) {
Write-Host "虚拟化固件: 启用" -ForegroundColor Green
} else {
Write-Host "虚拟化固件: 禁用" -ForegroundColor Red
}

# 总结
Write-Host "`n测试总结:" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray
if (-not $hypervisor.HypervisorPresent -and $virtualizationEnabled) {
Write-Host "✓ 虚拟化功能已成功释放" -ForegroundColor Green
Write-Host "✓ 可以正常使用第三方虚拟化软件" -ForegroundColor Green
} else {
Write-Host "✗ 虚拟化功能可能未完全释放" -ForegroundColor Red
Write-Host "✗ 建议重新运行dgreadiness工具" -ForegroundColor Yellow
}

恢复操作(如需重新启用)

步骤14:重新启用VBS功能

使用dgreadiness工具重新启用:

# 导航到工具目录
Set-Location "C:\Tools\dgreadiness_v3.6"

# 重新启用VBS
Write-Host "开始重新启用虚拟化安全..." -ForegroundColor Cyan
.\DG_Readiness_Tool_v3.6.ps1 -Enable -AutoReboot

Write-Host "命令执行完成,系统将自动重启" -ForegroundColor Green

仅重新启用HVCI:

# 仅启用HVCI(内存完整性)
Write-Host "开始重新启用HVCI(内存完整性)..." -ForegroundColor Cyan
.\DG_Readiness_Tool_v3.6.ps1 -Enable -HVCI -AutoReboot

Write-Host "命令执行完成,系统将自动重启" -ForegroundColor Green

通过Windows安全中心启用:

# 打开核心隔离设置
Start-Process "ms-settings:windowssecurity-coreisolation"

Write-Host "在核心隔离页面中:" -ForegroundColor Cyan
Write-Host "1. 点击'核心隔离详细信息'" -ForegroundColor White
Write-Host "2. 打开'内存完整性'开关" -ForegroundColor White
Write-Host "3. 点击'立即重启'" -ForegroundColor White

恢复注册表备份:

# 查找最新的备份目录
$backupDirs = Get-ChildItem -Path "C:\" -Filter "DGReadiness_Backup_*" |
Sort-Object LastWriteTime -Descending

if ($backupDirs.Count -gt 0) {
$latestBackup = $backupDirs[0].FullName
Write-Host "找到最新备份: $latestBackup" -ForegroundColor Green

$response = Read-Host "是否恢复注册表备份?(Y/N)"
if ($response -eq 'Y' -or $response -eq 'y') {
# 导入所有.reg文件
$regFiles = Get-ChildItem -Path $latestBackup -Filter "*.reg"
foreach ($regFile in $regFiles) {
Write-Host "正在恢复: $($regFile.Name)" -ForegroundColor Cyan
reg import $regFile.FullName
}

Write-Host "注册表备份已恢复,需要重启系统" -ForegroundColor Green
$response = Read-Host "是否立即重启?(Y/N)"
if ($response -eq 'Y' -or $response -eq 'y') {
Restart-Computer
}
}
} else {
Write-Host "未找到备份目录" -ForegroundColor Yellow
}

注意事项

操作风险警告

1. 安全性降低风险

风险描述:
禁用VBS/HVCI会显著降低系统的安全防护能力,使系统更容易受到以下攻击:

攻击类型 风险等级 说明
内核级Rootkit 🔴 高 恶意代码可直接修改内核内存
驱动程序漏洞利用 🔴 高 未签名驱动可被恶意利用
凭据窃取 🔴 高 Credential Guard禁用后,LSA保护减弱
内存破坏攻击 🔴 高 W+X内存页面可能被滥用
零日漏洞利用 🟡 中HVCI可阻止的部分攻击面将暴露

安全建议:

# 在禁用VBS后,建议加强其他安全措施
Write-Host "建议采取的补充安全措施:" -ForegroundColor Cyan
Write-Host "1. 确保Windows Defender实时保护始终启用" -ForegroundColor White
Write-Host "2. 定期更新系统和驱动程序" -ForegroundColor White
Write-Host "3. 仅从可信来源安装软件" -ForegroundColor White
Write-Host "4. 使用强密码和多因素认证" -ForegroundColor White
Write-Host "5. 定期备份重要数据" -ForegroundColor White
Write-Host "6. 限制管理员账户使用" -ForegroundColor White
Write-Host "7. 启用网络防火墙" -ForegroundColor White

2. 功能依赖风险

受影响的Windows功能:

Write-Host "禁用VBS后,以下功能可能无法使用:" -ForegroundColor Yellow
Write-Host "================================" -ForegroundColor Gray
Write-Host "✗ Windows Defender Credential Guard" -ForegroundColor Red
Write-Host "✗ Windows Defender Application Guard" -ForegroundColor Red
Write-Host "✗ Windows Sandbox(Windows沙盒)" -ForegroundColor Red
Write-Host "✗ WSL2(Windows子系统 for Linux 2)" -ForegroundColor Red
Write-Host "✗ 某些Windows Hello功能" -ForegroundColor Red
Write-Host "✗ 内存完整性保护" -ForegroundColor Red
Write-Host "✗ 内核隔离功能" -ForegroundColor Red

检查依赖功能:

# 检查Windows功能状态
Write-Host "检查Windows功能状态:" -ForegroundColor Cyan
$features = @(
@{Name="Containers-DisposableClientVM"; Desc="Windows Sandbox"},
@{Name="Microsoft-Hyper-V-All"; Desc="Hyper-V"},
@{Name="VirtualMachinePlatform"; Desc="虚拟机平台"},
@{Name="Windows-Defender-ApplicationGuard"; Desc="Application Guard"}
)

foreach ($feature in $features) {
$state = Get-WindowsOptionalFeature -Online -FeatureName $feature.Name -ErrorAction SilentlyContinue
if ($state -and $state.State -eq "Enabled") {
Write-Host "$($feature.Desc): 启用" -ForegroundColor Yellow
Write-Host " 注意:此功能可能受影响" -ForegroundColor Gray
}
}

3. 系统稳定性风险

可能遇到的问题:

  1. 驱动程序加载异常
# 监控驱动加载错误
Write-Host "监控驱动加载错误(事件查看器):" -ForegroundColor Cyan
Get-WinEvent -FilterHashtable @{
LogName = 'System'
ProviderName = 'Microsoft-Windows-DriverFrameworks-UserMode'
Level = 2
} -MaxEvents 10 | Format-List TimeCreated, Message
  1. 系统更新失败
# 检查Windows更新状态
Write-Host "检查Windows更新历史:" -ForegroundColor Cyan
Get-WindowsUpdateLog | Select-String "Error", "Failed" | Select-Object -First 10
  1. 性能回归
# 性能基准测试建议
Write-Host "建议进行性能基准测试:" -ForegroundColor Cyan
Write-Host "1. 使用PCMark 10进行综合性能测试" -ForegroundColor White
Write-Host "2. 使用CrystalDiskMark测试磁盘性能" -ForegroundColor White
Write-Host "3. 使用3DMark测试图形性能" -ForegroundColor White
Write-Host "4. 记录禁用前后的性能数据对比" -ForegroundColor White

系统要求

硬件要求

组件 最低要求 推荐配置 说明
处理器 64位CPU Intel Core i5 / AMD Ryzen 5及以上 必须支持虚拟化扩展
虚拟化支持 Intel VT-x / AMD-V - BIOS中必须启用
SLAT Intel EPT / AMD RVI - 二级地址转换
内存 4GB 8GB及以上 VBS占用约1-2GB内存
TPM TPM 1.2 TPM 2.0 Credential Guard需要TPM 2.0
固件 UEFI 2.3.1 最新UEFI版本 必须支持Secure Boot
存储 20GB可用空间 50GB及以上 用于日志和备份

检查硬件兼容性:

# 硬件兼容性检查脚本
Write-Host "硬件兼容性检查:" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray

# 1. 检查CPU
$cpu = Get-CimInstance -ClassName Win32_Processor
Write-Host "处理器信息:" -ForegroundColor Yellow
Write-Host " 名称: $($cpu.Name)" -ForegroundColor White
Write-Host " 架构: $($cpu.Architecture)" -ForegroundColor White
Write-Host " 核心数: $($cpu.NumberOfCores)" -ForegroundColor White
Write-Host " 虚拟化: $(if ($cpu.VirtualizationFirmwareEnabled) { '启用' } else { '禁用' })" -ForegroundColor $(if ($cpu.VirtualizationFirmwareEnabled) { "Green" } else { "Red" })
Write-Host " SLAT: $(if ($cpu.SecondLevelAddressTranslationExtensions) { '支持' } else { '不支持' })" -ForegroundColor $(if ($cpu.SecondLevelAddressTranslationExtensions) { "Green" } else { "Red" })

# 2. 检查内存
$memory = Get-CimInstance -ClassName Win32_PhysicalMemory
$totalMemory = ($memory | Measure-Object -Property Capacity -Sum).Sum / 1GB
Write-Host "`n内存信息:" -ForegroundColor Yellow
Write-Host " 总容量: $([math]::Round($totalMemory, 2)) GB" -ForegroundColor White

if ($totalMemory -lt 4) {
Write-Host " 警告:内存低于最低要求" -ForegroundColor Red
} elseif ($totalMemory -lt 8) {
Write-Host " 提示:建议升级到8GB或更多" -ForegroundColor Yellow
} else {
Write-Host " 状态:满足推荐配置" -ForegroundColor Green
}

# 3. 检查TPM
$tpm = Get-CimInstance -ClassName Win32_Tpm -Namespace root\cimv2\security\microsofttpm -ErrorAction SilentlyContinue
if ($tpm) {
Write-Host "`nTPM信息:" -ForegroundColor Yellow
Write-Host " 版本: $($tpm.SpecVersion)" -ForegroundColor White
Write-Host " 状态: $(if ($tpm.IsEnabled_InitialValue) { '启用' } else { '禁用' })" -ForegroundColor $(if ($tpm.IsEnabled_InitialValue) { "Green" } else { "Red" })

if ($tpm.SpecVersion -match "2\.0") {
Write-Host " 状态:支持Credential Guard" -ForegroundColor Green
} else {
Write-Host " 提示:建议升级到TPM 2.0" -ForegroundColor Yellow
}
} else {
Write-Host "`nTPM信息:未检测到TPM" -ForegroundColor Red
}

# 4. 检查UEFI和Secure Boot
$firmware = Get-CimInstance -ClassName Win32_BIOS
Write-Host "`n固件信息:" -ForegroundColor Yellow
Write-Host " 版本: $($firmware.SMBIOSBIOSVersion)" -ForegroundColor White
Write-Host " 日期: $($firmware.ReleaseDate)" -ForegroundColor White

# 检查Secure Boot状态(需要管理员权限)
try {
$secureBoot = Confirm-SecureBootUEFI
Write-Host " Secure Boot: 启用" -ForegroundColor Green
} catch {
Write-Host " Secure Boot: 禁用或无法检测" -ForegroundColor Yellow
}

# 5. 检查可用磁盘空间
$systemDrive = Get-PSDrive -Name C
$freeSpaceGB = $systemDrive.Free / 1GB
Write-Host "`n磁盘空间(C盘):" -ForegroundColor Yellow
Write-Host " 可用空间: $([math]::Round($freeSpaceGB, 2)) GB" -ForegroundColor White

if ($freeSpaceGB -lt 20) {
Write-Host " 警告:可用空间不足20GB" -ForegroundColor Red
} elseif ($freeSpaceGB -lt 50) {
Write-Host " 提示:建议保持至少50GB可用空间" -ForegroundColor Yellow
} else {
Write-Host " 状态:满足要求" -ForegroundColor Green
}

软件要求

软件 最低版本 推荐版本 说明
Windows 10 1607 21H2或更新 家庭版/专业版/企业版
Windows 11 21H2 23H2或更新 家庭版/专业版/企业版
Windows Server 2016 14393 最新更新版 标准版/数据中心版
Windows Server 2019 17763 最新更新版 标准版/数据中心版
Windows Server 2022 20348 最新更新版 标准版/数据中心版
PowerShell 5.1 7.x或更新 用于运行工具脚本
.NET Framework 4.7.2 4.8或更新 某些组件依赖

检查系统版本:

# 系统版本检查
Write-Host "系统版本检查:" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray

$os = Get-CimInstance -ClassName Win32_OperatingSystem
Write-Host "操作系统: $($os.Caption)" -ForegroundColor White
Write-Host "版本: $($os.Version)" -ForegroundColor White
Write-Host "构建号: $($os.BuildNumber)" -ForegroundColor White
Write-Host "服务包: $($os.ServicePackMajorVersion).$($os.ServicePackMinorVersion)" -ForegroundColor White

# 解析版本号
$buildNumber = [int]$os.BuildNumber
Write-Host "`n版本分析:" -ForegroundColor Yellow

if ($os.Caption -match "Windows 11") {
if ($buildNumber -ge 26100) {
Write-Host " Windows 11 24H2/25H2 - 最新版本" -ForegroundColor Green
} elseif ($buildNumber -ge 22631) {
Write-Host " Windows 11 23H2" -ForegroundColor Green
} elseif ($buildNumber -ge 22000) {
Write-Host " Windows 11 21H2/22H2" -ForegroundColor Green
}
} elseif ($os.Caption -match "Windows 10") {
if ($buildNumber -ge 19045) {
Write-Host " Windows 10 22H2" -ForegroundColor Green
} elseif ($buildNumber -ge 19044) {
Write-Host " Windows 10 21H2" -ForegroundColor Green
} elseif ($buildNumber -ge 14393) {
Write-Host " Windows 10 1607-21H1" -ForegroundColor Yellow
}
} elseif ($os.Caption -match "Windows Server") {
if ($buildNumber -ge 20348) {
Write-Host " Windows Server 2022" -ForegroundColor Green
} elseif ($buildNumber -ge 17763) {
Write-Host " Windows Server 2019" -ForegroundColor Green
} elseif ($buildNumber -ge 14393) {
Write-Host " Windows Server 2016" -ForegroundColor Yellow
}
}

# 检查PowerShell版本
Write-Host "`nPowerShell版本:" -ForegroundColor Yellow
$psVersion = $PSVersionTable.PSVersion
Write-Host " 版本: $($psVersion.Major).$($psVersion.Minor).$($psVersion.Build)" -ForegroundColor White
Write-Host " 版本: $($PSVersionTable.PSEdition)" -ForegroundColor White

if ($psVersion.Major -ge 7) {
Write-Host " 状态:使用PowerShell 7+,推荐" -ForegroundColor Green
} else {
Write-Host " 提示:建议升级到PowerShell 7" -ForegroundColor Yellow
}

# 检查.NET Framework版本
Write-Host "`n.NET Framework版本:" -ForegroundColor Yellow
$netVersions = Get-ChildItem "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" -ErrorAction SilentlyContinue
if ($netVersions) {
$release = (Get-ItemProperty $netVersions.PSPath).Release
Write-Host " Release: $release" -ForegroundColor White

if ($release -ge 528040) {
Write-Host " 版本:4.8或更新 - 满足要求" -ForegroundColor Green
} elseif ($release -ge 461808) {
Write-Host " 版本:4.7.2 - 满足最低要求" -ForegroundColor Yellow
} else {
Write-Host " 版本:低于4.7.2 - 不满足要求" -ForegroundColor Red
}
} else {
Write-Host " 状态:未检测到.NET Framework 4.x" -ForegroundColor Red
}

恢复方法

方法1:使用dgreadiness工具重新启用

重新启用所有VBS功能:

# 导航到工具目录
Set-Location "C:\Tools\dgreadiness_v3.6"

# 重新启用VBS
Write-Host "开始重新启用虚拟化安全功能..." -ForegroundColor Cyan
Write-Host "此操作将恢复以下功能:" -ForegroundColor Yellow
Write-Host " - Device Guard" -ForegroundColor Gray
Write-Host " - Credential Guard" -ForegroundColor Gray
Write-Host " - HVCI(内存完整性)" -ForegroundColor Gray
Write-Host ""

# 请求确认
$confirmation = Read-Host "是否继续?(Y/N)"
if ($confirmation -ne 'Y' -and $confirmation -ne 'y') {
Write-Host "操作已取消" -ForegroundColor Yellow
exit
}

# 执行启用命令
Write-Host "执行启用命令..." -ForegroundColor Cyan
.\DG_Readiness_Tool_v3.6.ps1 -Enable -AutoReboot

Write-Host "命令执行完成,系统将自动重启" -ForegroundColor Green

仅重新启用HVCI:

# 仅启用HVCI
Write-Host "开始重新启用HVCI(内存完整性)..." -ForegroundColor Cyan
Write-Host "注意:仅恢复内存完整性保护" -ForegroundColor Yellow
Write-Host ""

# 请求确认
$confirmation = Read-Host "是否继续?(Y/N)"
if ($confirmation -ne 'Y' -and $confirmation -ne 'y') {
Write-Host "操作已取消" -ForegroundColor Yellow
exit
}

# 执行启用命令
Write-Host "执行启用命令..." -ForegroundColor Cyan
.\DG_Readiness_Tool_v3.6.ps1 -Enable -HVCI -AutoReboot

Write-Host "命令执行完成,系统将自动重启" -ForegroundColor Green

方法2:通过组策略恢复

恢复Device Guard组策略:

# 启动组策略编辑器
Start-Process gpedit.msc

Write-Host "在组策略编辑器中:" -ForegroundColor Cyan
Write-Host "1. 导航到:计算机配置 → 管理模板 → 系统 → Device Guard" -ForegroundColor White
Write-Host "2. 找到'启用基于虚拟化的安全性'" -ForegroundColor White
Write-Host "3. 设置为'未配置'或'已启用'" -ForegroundColor White
Write-Host "4. 点击'应用'和'确定'" -ForegroundColor White
Write-Host "5. 运行以下命令更新组策略:" -ForegroundColor Yellow
Write-Host " gpupdate /force" -ForegroundColor Gray

更新组策略:

# 强制更新组策略
Write-Host "正在更新组策略..." -ForegroundColor Cyan
gpupdate /force

Write-Host "组策略已更新,建议重启系统" -ForegroundColor Green

方法3:通过注册表恢复

恢复Device Guard注册表项:

# 恢复Device Guard注册表配置
Write-Host "恢复Device Guard注册表配置..." -ForegroundColor Cyan

$deviceGuardPath = "HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard"

# 设置基本配置
Set-ItemProperty -Path $deviceGuardPath -Name "EnableVirtualizationBasedSecurity" -Value 1 -Type DWord -ErrorAction SilentlyContinue
Set-ItemProperty -Path $deviceGuardPath -Name "RequirePlatformSecurityFeatures" -Value 1 -Type DWord -ErrorAction SilentlyContinue

# 启用HVCI
$hvciPath = "$deviceGuardPath\Scenarios\HypervisorEnforcedCodeIntegrity"
Set-ItemProperty -Path $hvciPath -Name "Enabled" -Value 1 -Type DWord -ErrorAction SilentlyContinue

# 启用Credential Guard
$lsaPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa"
Set-ItemProperty -Path $lsaPath -Name "LsaCfgFlags" -Value 1 -Type DWord -ErrorAction SilentlyContinue

Write-Host "注册表配置已恢复" -ForegroundColor Green
Write-Host "需要重启系统以使更改生效" -ForegroundColor Yellow

恢复BCD配置:

# 恢复BCD配置以启用VBS
Write-Host "恢复BCD配置..." -ForegroundColor Cyan

# 启用hypervisor启动
bcdedit /set hypervisorlaunchtype auto
bcdedit /set vsmlaunchtype auto

Write-Host "BCD配置已恢复" -ForegroundColor Green
Write-Host "需要重启系统以使更改生效" -ForegroundColor Yellow

方法4:从备份恢复

恢复之前创建的备份:

# 查找最新的备份目录
$backupDirs = Get-ChildItem -Path "C:\" -Filter "DGReadiness_Backup_*" |
Sort-Object LastWriteTime -Descending

if ($backupDirs.Count -gt 0) {
$latestBackup = $backupDirs[0].FullName
Write-Host "找到最新备份: $latestBackup" -ForegroundColor Green

# 显示备份内容
Write-Host "`n备份内容:" -ForegroundColor Cyan
Get-ChildItem -Path $latestBackup | Format-Table Name, Length, LastWriteTime -AutoSize

$response = Read-Host "是否恢复此备份?(Y/N)"
if ($response -eq 'Y' -or $response -eq 'y') {
# 恢复注册表文件
$regFiles = Get-ChildItem -Path $latestBackup -Filter "*.reg"
Write-Host "`n正在恢复注册表备份..." -ForegroundColor Cyan

foreach ($regFile in $regFiles) {
Write-Host "恢复: $($regFile.Name)" -ForegroundColor White
reg import $regFile.FullName
}

Write-Host "注册表备份已恢复" -ForegroundColor Green

# 恢复BCD配置
$bcdBackup = Get-ChildItem -Path $latestBackup -Filter "BCD_Backup.txt"
if ($bcdBackup) {
Write-Host "`nBCD配置备份内容:" -ForegroundColor Cyan
Get-Content $bcdBackup.FullName | Select-Object -First 20

$response = Read-Host "是否手动恢复BCD配置?(Y/N)"
if ($response -eq 'Y' -or $response -eq 'y') {
Write-Host "请根据备份内容手动执行BCD命令" -ForegroundColor Yellow
}
}

Write-Host "`n备份恢复完成,需要重启系统" -ForegroundColor Green
$response = Read-Host "是否立即重启?(Y/N)"
if ($response -eq 'Y' -or $response -eq 'y') {
Restart-Computer
}
}
} else {
Write-Host "未找到备份目录" -ForegroundColor Yellow
}

方法5:使用系统还原点

恢复到之前的系统还原点:

# 列出可用的还原点
Write-Host "可用的系统还原点:" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray

$restorePoints = Get-ComputerRestorePoint | Sort-Object CreationTime -Descending
$restorePoints | Select-Object @{N="序号";E={$global:i=0}{$global:i++;$global:i}},
SequenceNumber,
Description,
CreationTime,
@{N="类型";E={$_.RestorePointType}} |
Format-Table -AutoSize

if ($restorePoints.Count -gt 0) {
Write-Host "`n输入要恢复的还原点序号(0取消):" -NoNewline
$selection = Read-Host

if ($selection -match "^\d+$" -and [int]$selection -gt 0 -and [int]$selection -le $restorePoints.Count) {
$selectedPoint = $restorePoints[[int]$selection - 1]

Write-Host "`n选中的还原点:" -ForegroundColor Cyan
Write-Host " 描述: $($selectedPoint.Description)" -ForegroundColor White
Write-Host " 时间: $($selectedPoint.CreationTime)" -ForegroundColor White

$confirmation = Read-Host "`n确认恢复到此还原点?此操作不可撤销(Y/N)"
if ($confirmation -eq 'Y' -or $confirmation -eq 'y') {
Write-Host "正在系统还原..." -ForegroundColor Cyan
Restore-Computer -RestorePoint $selectedPoint.SequenceNumber

Write-Host "系统还原已启动,计算机将重启" -ForegroundColor Green
Start-Sleep -Seconds 5
Restart-Computer
}
} else {
Write-Host "操作已取消" -ForegroundColor Yellow
}
} else {
Write-Host "没有可用的系统还原点" -ForegroundColor Yellow
}

备份建议

关键备份项清单

# 创建完整备份脚本
Write-Host "创建完整备份..." -ForegroundColor Cyan

# 1. 创建备份目录
$backupRoot = "C:\DGReadiness_Backup_$(Get-Date -Format 'yyyyMMdd_HHmmss')"
New-Item -ItemType Directory -Path $backupRoot -Force | Out-Null
Write-Host "备份目录: $backupRoot" -ForegroundColor Green

# 2. 备份注册表
Write-Host "`n[1/5] 备份注册表..." -ForegroundColor Cyan
$regBackupDir = "$backupRoot\Registry"
New-Item -ItemType Directory -Path $regBackupDir -Force | Out-Null

$regPaths = @(
"HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard",
"HKLM:\SYSTEM\CurrentControlSet\Control\Lsa",
"HKLM:\SOFTWARE\Policies\Microsoft\Windows\Device Guard",
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce"
)

foreach ($path in $regPaths) {
$fileName = $path.Replace('\', '_').Replace(':', '') + ".reg"
$filePath = Join-Path $regBackupDir $fileName
reg export $path $filePath /y
Write-Host " 已备份: $path" -ForegroundColor Green
}

# 3. 备份BCD配置
Write-Host "`n[2/5] 备份BCD配置..." -ForegroundColor Cyan
$bcdBackup = "$backupRoot\BCD_Configuration.txt"
bcdedit /enum all > $bcdBackup
Write-Host " 已备份: BCD配置" -ForegroundColor Green

# 4. 备份系统信息
Write-Host "`n[3/5] 备份系统信息..." -ForegroundColor Cyan
$sysInfoBackup = "$backupRoot\System_Info.txt"
systeminfo > $sysInfoBackup
Write-Host " 已备份: 系统信息" -ForegroundColor Green

# 5. 备份当前VBS状态
Write-Host "`n[4/5] 备份VBS状态..." -ForegroundColor Cyan
$vbsBackup = "$backupRoot\VBS_Status.txt"
$vbsStatus = Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard
$vbsStatus | Out-File -FilePath $vbsBackup
Write-Host " 已备份: VBS状态" -ForegroundColor Green

# 6. 创建系统还原点
Write-Host "`n[5/5] 创建系统还原点..." -ForegroundColor Cyan
$restorePointDesc = "Before DGReadiness Operation - $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')"
try {
Checkpoint-Computer -Description $restorePointDesc -RestorePointType "MODIFY_SETTINGS"
Write-Host " 已创建系统还原点" -ForegroundColor Green
} catch {
Write-Host " 系统还原点创建失败: $_" -ForegroundColor Red
}

# 7. 生成备份清单
Write-Host "`n生成备份清单..." -ForegroundColor Cyan
$manifestPath = "$backupRoot\Backup_Manifest.txt"
$manifestContent = @"
dgreadiness操作备份清单
================================
备份时间: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')
备份目录: $backupRoot

备份内容:
--------
1. 注册表备份: $(Join-Path $backupRoot "Registry")
2. BCD配置: $bcdBackup
3. 系统信息: $sysInfoBackup
4. VBS状态: $vbsBackup
5. 系统还原点: $restorePointDesc

备份文件列表:
--------
"@

Get-ChildItem -Path $backupRoot -Recurse | ForEach-Object {
$manifestContent += "$($_.FullName)`r`n"
}

$manifestContent | Out-File -FilePath $manifestPath
Write-Host " 已生成备份清单" -ForegroundColor Green

# 完成
Write-Host "`n================================" -ForegroundColor Gray
Write-Host "备份完成!" -ForegroundColor Green
Write-Host "备份目录: $backupRoot" -ForegroundColor Cyan
Write-Host "备份清单: $manifestPath" -ForegroundColor Cyan
Write-Host ""
Write-Host "建议:将备份目录复制到外部存储设备" -ForegroundColor Yellow

自动化备份脚本

创建定时备份任务:

# 创建每日自动备份脚本
$backupScript = @'
# 自动备份脚本
$backupRoot = "C:\DGReadiness_AutoBackup_$(Get-Date -Format 'yyyyMMdd')"
New-Item -ItemType Directory -Path $backupRoot -Force | Out-Null

# 备份注册表
$regBackupDir = "$backupRoot\Registry"
New-Item -ItemType Directory -Path $regBackupDir -Force | Out-Null

$regPaths = @(
"HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard",
"HKLM:\SYSTEM\CurrentControlSet\Control\Lsa"
)

foreach ($path in $regPaths) {
$fileName = $path.Replace('\', '_').Replace(':', '') + ".reg"
$filePath = Join-Path $regBackupDir $fileName
reg export $path $filePath /y
}

# 备份VBS状态
$vbsBackup = "$backupRoot\VBS_Status.txt"
Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard | Out-File -FilePath $vbsBackup

# 清理30天前的旧备份
$oldBackups = Get-ChildItem -Path "C:\" -Filter "DGReadiness_AutoBackup_*" |
Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30) }

foreach ($oldBackup in $oldBackups) {
Remove-Item -Path $oldBackup.FullName -Recurse -Force
}
'@

# 保存脚本
$scriptPath = "C:\Scripts\AutoBackup_DGReadiness.ps1"
New-Item -ItemType Directory -Path (Split-Path $scriptPath) -Force | Out-Null
$backupScript | Out-File -FilePath $scriptPath -Encoding UTF8

Write-Host "自动备份脚本已创建: $scriptPath" -ForegroundColor Green

# 创建计划任务
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$scriptPath`""
$trigger = New-ScheduledTaskTrigger -Daily -At "02:00"
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -DontStopOnIdleEnd
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest

Register-ScheduledTask -TaskName "AutoBackup DGReadiness" -Action $action -Trigger $trigger -Settings $settings -Principal $Principal -Force

Write-Host "计划任务已创建:AutoBackup DGReadiness" -ForegroundColor Green
Write-Host "执行时间:每天凌晨02:00" -ForegroundColor Yellow

常见问题解答

错误代码与问题解决方案

问题1:执行策略错误

错误信息:

无法加载文件 DG_Readiness_Tool_v3.6.ps1,因为在此系统上禁止运行脚本。
有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。

错误代码: 无特定错误代码
原因: PowerShell执行策略限制
解决方案:

# 临时解决方案(推荐)
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
Write-Host "✓ 执行策略已临时设置为Bypass" -ForegroundColor Green

# 验证设置
Write-Host "当前执行策略: $(Get-ExecutionPolicy -Scope Process)" -ForegroundColor Cyan

# 现在可以运行脚本了
.\DG_Readiness_Tool_v3.6.ps1 -Disable -HVCI

永久解决方案:

# 查看所有执行策略
Get-ExecutionPolicy -List

# 为当前用户设置RemoteSigned
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force

# 或设置为Unsecured(不推荐,安全风险高)
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force

问题2:权限不足错误

错误信息:

访问路径 'C:\Windows\System32\drivers\' 被拒绝。

您需要管理员权限才能运行此脚本。

错误代码: ERROR_ACCESS_DENIED (5)
原因: 缺少管理员权限
解决方案:

# 方法1:自动提升权限(添加到脚本开头)
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
exit
}

# 方法2:检查当前权限
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
$isAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

if (-not $isAdmin) {
Write-Host "✗ 需要管理员权限" -ForegroundColor Red
Write-Host "请右键点击PowerShell,选择'以管理员身份运行'" -ForegroundColor Yellow
exit
} else {
Write-Host "✓ 已获得管理员权限" -ForegroundColor Green
}

问题3:工具无法找到

错误信息:

术语 'DG_Readiness_Tool_v3.6.ps1' 无法被识别为 cmdlet、函数、脚本文件或可运行程序的名称。

错误代码: ERROR_FILE_NOT_FOUND (2)
原因: 脚本文件不存在或路径错误
解决方案:

# 检查文件是否存在
$toolPath = "C:\Tools\dgreadiness_v3.6\DG_Readiness_Tool_v3.6.ps1"

if (Test-Path $toolPath) {
Write-Host "✓ 工具脚本存在" -ForegroundColor Green
} else {
Write-Host "✗ 工具脚本不存在" -ForegroundColor Red
Write-Host "请检查路径是否正确" -ForegroundColor Yellow

# 搜索可能的文件位置
Write-Host "`n正在搜索工具脚本..." -ForegroundColor Cyan
$possiblePaths = @(
"$env:USERPROFILE\Downloads\dgreadiness_v3.6",
"C:\Tools\dgreadiness_v3.6",
"D:\Tools\dgreadiness_v3.6"
)

foreach ($path in $possiblePaths) {
if (Test-Path $path) {
Write-Host "找到目录: $path" -ForegroundColor Green
$files = Get-ChildItem -Path $path -Filter "*.ps1"
foreach ($file in $files) {
Write-Host " - $($file.Name)" -ForegroundColor Gray
}
}
}
}

# 正确的执行方式
if (Test-Path $toolPath) {
Set-Location (Split-Path $toolPath)
.\DG_Readiness_Tool_v3.6.ps1 -Disable -HVCI
}

问题4:VBS无法禁用

错误信息:

禁用操作完成后,重启系统,msinfo32仍显示"基于虚拟化的安全性:正在运行"

错误代码: 无特定错误代码
原因: 可能的原因包括:

  1. Windows Hello VBS隐藏依赖(Windows 11 24H2/25H2)
  2. 组策略强制启用
  3. UEFI锁未解除
  4. 注册表配置未完全清理

解决方案:

# 综合解决方案:完整清理VBS配置
Write-Host "开始完整清理VBS配置..." -ForegroundColor Cyan

# 1. 禁用Windows Hello VBS(Windows 11 24H2/25H2关键修复)
Write-Host "`n[1/6] 禁用Windows Hello VBS..." -ForegroundColor Cyan
$windowsHelloPath = "HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\WindowsHello"
if (Test-Path $windowsHelloPath) {
Set-ItemProperty -Path $windowsHelloPath -Name "Enabled" -Value 0 -Type DWord -Force
Write-Host " ✓ Windows Hello VBS已禁用" -ForegroundColor Green
} else {
Write-Host " - Windows Hello VBS路径不存在" -ForegroundColor Gray
}

# 2. 禁用Device Guard相关注册表项
Write-Host "`n[2/6] 清理Device Guard注册表..." -ForegroundColor Cyan
$deviceGuardPath = "HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard"
if (Test-Path $deviceGuardPath) {
# 设置基本配置为禁用
Set-ItemProperty -Path $deviceGuardPath -Name "EnableVirtualizationBasedSecurity" -Value 0 -Type DWord -Force
Set-ItemProperty -Path $deviceGuardPath -Name "RequirePlatformSecurityFeatures" -Value 0 -Type DWord -Force

# 禁用所有场景
$scenarios = @("HypervisorEnforcedCodeIntegrity", "WindowsHello", "DeviceGuard")
foreach ($scenario in $scenarios) {
$scenarioPath = "$deviceGuardPath\Scenarios\$scenario"
if (Test-Path $scenarioPath) {
Set-ItemProperty -Path $scenarioPath -Name "Enabled" -Value 0 -Type DWord -Force
Write-Host " ✓ 已禁用: $scenario" -ForegroundColor Green
}
}
}

# 3. 清理LSA配置
Write-Host "`n[3/6] 清理LSA配置..." -ForegroundColor Cyan
$lsaPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa"
if (Test-Path $lsaPath) {
# 删除或禁用LsaCfgFlags
Remove-ItemProperty -Path $lsaPath -Name "LsaCfgFlags" -ErrorAction SilentlyContinue
Set-ItemProperty -Path $lsaPath -Name "LsaCfgFlags" -Value 0 -Type DWord -ErrorAction SilentlyContinue
Write-Host " ✓ LSA配置已清理" -ForegroundColor Green
}

# 4. 修改BCD配置
Write-Host "`n[4/6] 修改BCD配置..." -ForegroundColor Cyan
bcdedit /set hypervisorlaunchtype off
bcdedit /set vsmlaunchtype off
bcdedit /set `{current`} hypervisorlaunchtype off
bcdedit /set `{current`} vsmlaunchtype off
Write-Host " ✓ BCD配置已修改" -ForegroundColor Green

# 5. 禁用Windows功能
Write-Host "`n[5/6] 禁用Windows功能..." -ForegroundColor Cyan
$featuresToDisable = @(
"Microsoft-Hyper-V-All",
"Microsoft-Hyper-V",
"HypervisorPlatform",
"VirtualMachinePlatform",
"Containers-DisposableClientVM",
"Windows-Defender-ApplicationGuard"
)

foreach ($feature in $featuresToDisable) {
$state = Get-WindowsOptionalFeature -Online -FeatureName $feature -ErrorAction SilentlyContinue
if ($state -and $state.State -eq "Enabled") {
Disable-WindowsOptionalFeature -Online -FeatureName $feature -NoRestart
Write-Host " ✓ 已禁用: $feature" -ForegroundColor Green
}
}

# 6. 使用dgreadiness工具确认
Write-Host "`n[6/6] 使用dgreadiness工具确认..." -ForegroundColor Cyan
$dgToolPath = "C:\Tools\dgreadiness_v3.6\DG_Readiness_Tool_v3.6.ps1"
if (Test-Path $dgToolPath) {
Set-Location (Split-Path $dgToolPath)
.\DG_Readiness_Tool_v3.6.ps1 -Disable
Write-Host " ✓ dgreadiness工具已执行" -ForegroundColor Green
}

Write-Host "`n================================" -ForegroundColor Gray
Write-Host "配置清理完成!" -ForegroundColor Green
Write-Host "请立即重启系统" -ForegroundColor Yellow
Write-Host "重启后如出现SecConfig菜单,请按F3确认禁用" -ForegroundColor Yellow

处理UEFI锁:

# 检查是否有UEFI锁
$deviceGuardPath = "HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard"
$locked = (Get-ItemProperty -Path $deviceGuardPath -ErrorAction SilentlyContinue).Locked

if ($locked -eq 1) {
Write-Host "检测到UEFI锁" -ForegroundColor Yellow
Write-Host "需要在BIOS/UEFI中手动禁用以下选项:" -ForegroundColor Cyan
Write-Host "1. Virtualization Based Security (VBS)" -ForegroundColor White
Write-Host "2. Secure Boot" -ForegroundColor White
Write-Host "3. Intel SGX / AMD PSP" -ForegroundColor White
Write-Host ""
Write-Host "具体步骤:" -ForegroundColor Cyan
Write-Host "1. 重启电脑" -ForegroundColor White
Write-Host "2. 进入BIOS/UEFI设置(通常按F2、Del、F10等)" -ForegroundColor White
Write-Host "3. 找到Security或Advanced选项" -ForegroundColor White
Write-Host "4. 禁用VBS相关选项" -ForegroundColor White
Write-Host "5. 保存并退出" -ForegroundColor White
Write-Host "6. 重新运行此脚本" -ForegroundColor White
}

问题5:重启后蓝屏

错误信息:

系统重启后出现蓝屏(BSOD)
错误代码:CRITICAL_PROCESS_DIED 或 SYSTEM_SERVICE_EXCEPTION

错误代码:

  • CRITICAL_PROCESS_DIED (0xEF)
  • SYSTEM_SERVICE_EXCEPTION (0x3B)

原因: VBS驱动冲突或系统文件损坏
解决方案:

# 安全模式下修复
Write-Host "系统蓝屏修复方案:" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray
Write-Host "步骤1:进入安全模式" -ForegroundColor Yellow
Write-Host " - 强制关机3次,进入Windows恢复环境" -ForegroundColor White
Write-Host " - 选择'高级选项' → '启动设置' → '重启'" -ForegroundColor White
Write-Host " - 按4或F4进入安全模式" -ForegroundColor White
Write-Host ""

Write-Host "步骤2:运行修复命令" -ForegroundColor Yellow
Write-Host " 在安全模式下打开PowerShell(管理员),执行:" -ForegroundColor White
Write-Host ""
Write-Host " # 禁用VBS" -ForegroundColor Gray
Write-Host " bcdedit /set hypervisorlaunchtype off" -ForegroundColor Cyan
Write-Host " bcdedit /set vsmlaunchtype off" -ForegroundColor Cyan
Write-Host ""
Write-Host " # 修复系统文件" -ForegroundColor Gray
Write-Host " sfc /scannow" -ForegroundColor Cyan
Write-Host ""
Write-Host " # 修复映像" -ForegroundColor Gray
Write-Host " DISM /Online /Cleanup-Image /RestoreHealth" -ForegroundColor Cyan
Write-Host ""
Write-Host " # 恢复注册表" -ForegroundColor Gray
Write-Host " reg import C:\DGReadiness_Backup_*.reg" -ForegroundColor Cyan
Write-Host ""

Write-Host "步骤3:正常重启" -ForegroundColor Yellow
Write-Host " 重启系统,看是否正常启动" -ForegroundColor White
Write-Host ""

Write-Host "步骤4:使用系统还原" -ForegroundColor Yellow
Write-Host " 如果仍然蓝屏,使用系统还原点恢复" -ForegroundColor White
Write-Host " 或使用'重置此电脑'功能" -ForegroundColor White

自动化修复脚本:

# 系统修复脚本(需在安全模式下运行)
Write-Host "开始系统修复..." -ForegroundColor Cyan

# 1. 修复系统文件
Write-Host "[1/4] 修复系统文件..." -ForegroundColor Cyan
sfc /scannow

# 2. 修复Windows映像
Write-Host "[2/4] 修复Windows映像..." -ForegroundColor Cyan
DISM /Online /Cleanup-Image /CheckHealth
DISM /Online /Cleanup-Image /ScanHealth
DISM /Online /Cleanup-Image /RestoreHealth

# 3. 修复BCD
Write-Host "[3/4] 修复BCD配置..." -ForegroundColor Cyan
bcdedit /set hypervisorlaunchtype off
bcdedit /set vsmlaunchtype off
bcdedit /set {default} safeboot minimal

# 4. 修复注册表
Write-Host "[4/4] 恢复默认注册表配置..." -ForegroundColor Cyan
$deviceGuardPath = "HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard"
if (Test-Path $deviceGuardPath) {
Set-ItemProperty -Path $deviceGuardPath -Name "EnableVirtualizationBasedSecurity" -Value 0 -Type DWord -Force
Set-ItemProperty -Path $deviceGuardPath -Name "RequirePlatformSecurityFeatures" -Value 0 -Type DWord -Force
}

Write-Host "修复完成!重启系统" -ForegroundColor Green
Write-Host "重启后按F8进入启动菜单,选择'正常启动'" -ForegroundColor Yellow

问题6:虚拟化软件仍无法使用

错误信息:

VMware/VirtualBox仍显示"检测到Hypervisor"或VT-x不可用

错误代码: VMware: VMware unrecoverable error
原因: Hypervisor未完全卸载
解决方案:

# 完全移除Hyper-V和Hypervisor
Write-Host "完全移除Hyper-V和Hypervisor..." -ForegroundColor Cyan

# 1. 禁用所有Hyper-V相关功能
Write-Host "`n[1/4] 禁用Hyper-V功能..." -ForegroundColor Cyan
$hyperVFeatures = @(
"Microsoft-Hyper-V",
"Microsoft-Hyper-V-Management-PowerShell",
"Microsoft-Hyper-V-Management-Clients",
"Microsoft-Hyper-V-Tools",
"Microsoft-Hyper-V-Hypervisor",
"HypervisorPlatform",
"VirtualMachinePlatform"
)

foreach ($feature in $hyperVFeatures) {
$state = Get-WindowsOptionalFeature -Online -FeatureName $feature -ErrorAction SilentlyContinue
if ($state -and $state.State -eq "Enabled") {
Write-Host " 禁用: $feature" -ForegroundColor Yellow
Disable-WindowsOptionalFeature -Online -FeatureName $feature -NoRestart -ErrorAction SilentlyContinue
}
}

# 2. 修改BCD
Write-Host "`n[2/4] 修改BCD配置..." -ForegroundColor Cyan
bcdedit /set hypervisorlaunchtype off
bcdedit /set vsmlaunchtype off
bcdedit /set `{current`} isolatedcontext No
Write-Host " ✓ BCD已修改" -ForegroundColor Green

# 3. 删除相关服务
Write-Host "`n[3/4] 停止相关服务..." -ForegroundColor Cyan
$hvServices = @("hvboot", "HvHost", "vmms")
foreach ($service in $hvServices) {
$svc = Get-Service -Name $service -ErrorAction SilentlyContinue
if ($svc) {
Write-Host " 停止: $service" -ForegroundColor Yellow
Stop-Service -Name $service -Force -ErrorAction SilentlyContinue
Set-Service -Name $service -StartupType Disabled -ErrorAction SilentlyContinue
}
}

# 4. 验证
Write-Host "`n[4/4] 验证Hypervisor状态..." -ForegroundColor Cyan
$hypervisor = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object HypervisorPresent
if ($hypervisor.HypervisorPresent) {
Write-Host " ✗ Hypervisor仍存在" -ForegroundColor Red
Write-Host " 需要重启系统" -ForegroundColor Yellow
} else {
Write-Host " ✓ Hypervisor已移除" -ForegroundColor Green
}

Write-Host "`n请立即重启系统" -ForegroundColor Yellow

深度清理(最后手段):

# 深度清理Hypervisor组件
Write-Host "深度清理Hypervisor组件..." -ForegroundColor Cyan

# 警告提示
Write-Host "⚠️ 警告:此操作将删除所有Hyper-V相关组件" -ForegroundColor Red
Write-Host " 包括Windows Sandbox、WSL2等功能" -ForegroundColor Red
$confirmation = Read-Host "确认继续?(Y/N)"
if ($confirmation -ne 'Y' -and $confirmation -ne 'y') {
exit
}

# 1. 停止并删除服务
Write-Host "`n[1/5] 删除Hypervisor服务..." -ForegroundColor Cyan
$services = @("hvboot", "HvHost", "vmms", "vmcompute")
foreach ($serviceName in $services) {
$service = Get-WmiObject -Class Win32_Service -Filter "Name='$serviceName'" -ErrorAction SilentlyContinue
if ($service) {
Write-Host " 删除: $serviceName" -ForegroundColor Yellow
$service.StopService()
$service.Delete()
}
}

# 2. 删除驱动程序
Write-Host "`n[2/5] 删除Hypervisor驱动..." -ForegroundColor Cyan
$drivers = @("hvservice.sys", "hvboot.sys")
foreach ($driver in $drivers) {
$driverPath = "$env:SystemRoot\System32\drivers\$driver"
if (Test-Path $driverPath) {
Write-Host " 删除: $driver" -ForegroundColor Yellow
# 重命名而不是直接删除
Rename-Item -Path $driverPath -NewName "$driver.bak" -Force
}
}

# 3. 清理注册表
Write-Host "`n[3/5] 清理注册表..." -ForegroundColor Cyan
$regPaths = @(
"HKLM:\SYSTEM\CurrentControlSet\Services\hvboot",
"HKLM:\SYSTEM\CurrentControlSet\Services\HvHost",
"HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard"
)

foreach ($path in $regPaths) {
if (Test-Path $path) {
Write-Host " 清理: $path" -ForegroundColor Yellow
Remove-Item -Path $path -Recurse -Force -ErrorAction SilentlyContinue
}
}

# 4. 重置BCD
Write-Host "`n[4/5] 重置BCD..." -ForegroundColor Cyan
bcdedit /deletevalue {current} isolatedcontext
bcdedit /deletevalue {bootmgr} isolatedcontext
bcdedit /set hypervisorlaunchtype off
bcdedit /set vsmlaunchtype off

# 5. 最终验证
Write-Host "`n[5/5] 最终验证..." -ForegroundColor Cyan
$hypervisor = Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object HypervisorPresent
if ($hypervisor.HypervisorPresent) {
Write-Host " ⚠️ Hypervisor仍存在,可能需要重启多次" -ForegroundColor Yellow
} else {
Write-Host " ✓ Hypervisor已完全移除" -ForegroundColor Green
}

Write-Host "`n请立即重启系统" -ForegroundColor Yellow
Write-Host "如仍有问题,可能需要重新安装系统" -ForegroundColor Red

问题7:工具下载失败

错误信息:

从Microsoft下载页面下载失败,或下载的文件损坏

错误代码: ERROR_INTERNET_CANNOT_CONNECT
原因: 网络问题或官方链接失效
解决方案:

# 多源下载方案
Write-Host "dgreadiness工具多源下载方案" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray

# 源1:官方下载页
Write-Host "`n源1:Microsoft官方下载页" -ForegroundColor Green
Write-Host "URL: https://www.microsoft.com/en-us/download/details.aspx?id=53337" -ForegroundColor White
Write-Host "步骤:" -ForegroundColor Yellow
Write-Host " 1. 访问上述URL" -ForegroundColor White
Write-Host " 2. 选择语言" -ForegroundColor White
Write-Host " 3. 点击Download按钮" -ForegroundColor White
Write-Host " 4. 下载dgreadiness_v3.6.zip" -ForegroundColor White

# 源2:PowerShell直接下载
Write-Host "`n源2:PowerShell直接下载" -ForegroundColor Green
$directUrls = @(
"https://download.microsoft.com/download/6/4/1/641C3FAF-2C49-45D6-8E8A-C8FD93B2F7C3/dgreadiness_v3.6.zip",
"https://aka.ms/deviceguardreadiness"
)

foreach ($url in $directUrls) {
Write-Host "尝试下载: $url" -ForegroundColor Yellow
$outputPath = "$env:USERPROFILE\Downloads\dgreadiness_v3.6.zip"

try {
# 使用WebClient下载
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($url, $outputPath)

# 验证下载
if (Test-Path $outputPath) {
$fileInfo = Get-Item $outputPath
Write-Host " ✓ 下载成功: $($fileInfo.Length) 字节" -ForegroundColor Green
break
}
} catch {
Write-Host " ✗ 下载失败: $_" -ForegroundColor Red
}
}

# 源3:从另一台电脑复制
Write-Host "`n源3:从另一台电脑复制" -ForegroundColor Green
Write-Host "步骤:" -ForegroundColor Yellow
Write-Host " 1. 在另一台可访问的电脑上下载工具" -ForegroundColor White
Write-Host " 2. 通过U盘或网络共享复制到目标电脑" -ForegroundColor White
Write-Host " 3. 解压到C:\Tools\dgreadiness_v3.6" -ForegroundColor White

# 源4:使用备用下载工具
Write-Host "`n源4:使用备用下载工具" -ForegroundColor Green
Write-Host "可以使用以下工具下载:" -ForegroundColor Yellow
Write-Host " - Internet Explorer / Edge浏览器" -ForegroundColor White
Write-Host " - Firefox / Chrome浏览器" -ForegroundColor White
Write-Host " - 下载管理器(如Free Download Manager)" -ForegroundColor White

# 验证下载的文件
Write-Host "`n验证下载的文件..." -ForegroundColor Cyan
$downloadedFile = "$env:USERPROFILE\Downloads\dgreadiness_v3.6.zip"

if (Test-Path $downloadedFile) {
$fileInfo = Get-Item $downloadedFile
Write-Host "文件信息:" -ForegroundColor Yellow
Write-Host " 大小: $($fileInfo.Length) 字节" -ForegroundColor White
Write-Host " 修改时间: $($fileInfo.LastWriteTime)" -ForegroundColor White

# 预期大小:31.7 KB (32467 字节)
if ($fileInfo.Length -gt 30000 -and $fileInfo.Length -lt 50000) {
Write-Host " ✓ 文件大小正常" -ForegroundColor Green
} else {
Write-Host " ✗ 文件大小异常,可能损坏" -ForegroundColor Red
}

# 测试解压
Write-Host "`n测试解压..." -ForegroundColor Cyan
$testDir = "$env:TEMP\dgreadiness_test"
try {
Expand-Archive -Path $downloadedFile -DestinationPath $testDir -Force
Write-Host " ✓ 文件可以正常解压" -ForegroundColor Green

# 检查关键文件
$scriptFile = "$testDir\DG_Readiness_Tool_v3.6.ps1"
if (Test-Path $scriptFile) {
Write-Host " ✓ 主脚本文件存在" -ForegroundColor Green
}

# 清理测试目录
Remove-Item -Path $testDir -Recurse -Force
} catch {
Write-Host " ✗ 解压失败: $_" -ForegroundColor Red
}
} else {
Write-Host "✗ 下载的文件不存在" -ForegroundColor Red
}

问题8:Windows Hello问题

错误信息:

禁用VBS后,Windows Hello无法使用,提示"需要重新设置PIN"

错误代码: 无特定错误代码
原因: Windows Hello依赖VBS的安全隔离功能
解决方案:

# Windows Hello重新配置
Write-Host "Windows Hello重新配置方案" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray

Write-Host "问题说明:" -ForegroundColor Yellow
Write-Host "Windows Hello的某些功能(如人脸识别、指纹)依赖VBS" -ForegroundColor White
Write-Host "禁用VBS后,这些功能将无法使用" -ForegroundColor White
Write-Host ""

Write-Host "解决方案1:重新设置PIN(推荐)" -ForegroundColor Green
Write-Host "1. 打开设置 → 账户 → 登录选项" -ForegroundColor White
Write-Host "2. 找到Windows Hello PIN" -ForegroundColor White
Write-Host "3. 点击'我忘记了我的PIN'" -ForegroundColor White
Write-Host "4. 按提示重新设置PIN" -ForegroundColor White
Write-Host ""

Write-Host "解决方案2:使用密码登录" -ForegroundColor Green
Write-Host "1. 打开设置 → 账户 → 登录选项" -ForegroundColor White
Write-Host "2. 点击'添加'设置密码" -ForegroundColor White
Write-Host "3. 在登录界面使用密码代替PIN" -ForegroundColor White
Write-Host ""

Write-Host "解决方案3:禁用Windows Hello(不推荐)" -ForegroundColor Green
Write-Host "1. 打开设置 → 账户 → 登录选项" -ForegroundColor White
Write-Host "2. 移除Windows Hello相关选项" -ForegroundColor White
Write-Host "3. 仅使用密码登录" -ForegroundColor White
Write-Host ""

Write-Host "注意:" -ForegroundColor Yellow
Write-Host "如果需要使用Windows Hello的高级功能," -ForegroundColor White
Write-Host "需要重新启用VBS或使用支持VBS的Windows版本(如Enterprise版)" -ForegroundColor White

检查Windows Hello兼容性:

# 检查Windows Hello状态
Write-Host "检查Windows Hello兼容性..." -ForegroundColor Cyan

# 检查VBS状态
$vbsStatus = Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard
Write-Host "VBS状态: $($vbsStatus.VirtualizationBasedSecurityStatus)" -ForegroundColor $(if ($vbsStatus.VirtualizationBasedSecurityStatus -eq 0) { "Yellow" } else { "Green" })

# 检查Windows Hello VBS依赖
$windowsHelloPath = "HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\WindowsHello"
if (Test-Path $windowsHelloPath) {
$helloEnabled = (Get-ItemProperty -Path $windowsHelloPath).Enabled
Write-Host "Windows Hello VBS: $helloEnabled" -ForegroundColor $(if ($helloEnabled -eq 1) { "Green" } else { "Yellow" })
}

# 检查可用的Windows Hello功能
Write-Host "`n可用的Windows Hello功能:" -ForegroundColor Cyan
$helloCapabilities = Get-CimInstance -ClassName Win32_BiometricFeature -ErrorAction SilentlyContinue
if ($helloCapabilities) {
$helloCapabilities | Select-Object BiometricType, Description | Format-Table
} else {
Write-Host " 未检测到生物识别设备" -ForegroundColor Gray
}

# 给出建议
Write-Host "`n建议:" -ForegroundColor Yellow
if ($vbsStatus.VirtualizationBasedSecurityStatus -eq 0) {
Write-Host " - VBS已禁用,Windows Hello高级功能可能受限" -ForegroundColor White
Write-Host " - PIN登录仍可正常使用" -ForegroundColor White
Write-Host " - 人脸识别、指纹等功能可能无法使用" -ForegroundColor White
Write-Host " - 如需这些功能,请重新启用VBS" -ForegroundColor White
} else {
Write-Host " - VBS已启用,Windows Hello应可正常工作" -ForegroundColor White
}

操作失败排查清单

当使用dgreadiness工具关闭VBS功能失败时,按以下清单逐一排查:

# 操作失败排查清单
Write-Host "dgreadiness操作失败排查清单" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray

$issues = @()

# 检查1:管理员权限
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
$isAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

if (-not $isAdmin) {
$issues += @{
Item = "管理员权限"
Status = "❌ 失败"
Solution = "右键PowerShell,选择'以管理员身份运行'"
}
} else {
$issues += @{
Item = "管理员权限"
Status = "✓ 通过"
Solution = ""
}
}

# 检查2:PowerShell执行策略
$executionPolicy = Get-ExecutionPolicy -Scope Process
if ($executionPolicy -eq "Restricted") {
$issues += @{
Item = "执行策略"
Status = "❌ 失败"
Solution = "运行: Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass"
}
} else {
$issues += @{
Item = "执行策略"
Status = "✓ 通过"
Solution = ""
}
}

# 检查3:工具文件存在
$toolPath = "C:\Tools\dgreadiness_v3.6\DG_Readiness_Tool_v3.6.ps1"
if (-not (Test-Path $toolPath)) {
$issues += @{
Item = "工具文件"
Status = "❌ 失败"
Solution = "确认文件路径正确,或重新下载工具"
}
} else {
$issues += @{
Item = "工具文件"
Status = "✓ 通过"
Solution = ""
}
}

# 检查4:操作系统版本
$osVersion = [int](Get-CimInstance Win32_OperatingSystem).BuildNumber
if ($osVersion -lt 14393) {
$issues += @{
Item = "系统版本"
Status = "❌ 失败"
Solution = "需要Windows 10 1607或更新版本"
}
} else {
$issues += @{
Item = "系统版本"
Status = "✓ 通过"
Solution = ""
}
}

# 检查5:Windows Hello VBS(Windows 11 24H2/25H2)
if ($osVersion -ge 26100) {
$windowsHelloPath = "HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\WindowsHello"
if (Test-Path $windowsHelloPath) {
$helloEnabled = (Get-ItemProperty -Path $windowsHelloPath).Enabled
if ($helloEnabled -eq 1) {
$issues += @{
Item = "Windows Hello VBS"
Status = "⚠️ 警告"
Solution = "需要禁用Windows Hello VBS:Set-ItemProperty -Path '$windowsHelloPath' -Name 'Enabled' -Value 0"
}
}
}
}

# 检查6:UEFI锁
$deviceGuardPath = "HKLM:\SYSTEM\CurrentControlSet\Control\DeviceGuard"
$locked = (Get-ItemProperty -Path $deviceGuardPath -ErrorAction SilentlyContinue).Locked
if ($locked -eq 1) {
$issues += @{
Item = "UEFI锁"
Status = "❌ 失败"
Solution = "在BIOS/UEFI中禁用VBS相关选项"
}
}

# 检查7:组策略
$policyPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DeviceGuard"
if (Test-Path $policyPath) {
$policyEnabled = (Get-ItemProperty -Path $policyPath -ErrorAction SilentlyContinue).EnableDeviceGuard
if ($policyEnabled -eq 1) {
$issues += @{
Item = "组策略"
Status = "⚠️ 警告"
Solution = "通过gpedit.msc禁用Device Guard组策略"
}
}
}

# 显示检查结果
Write-Host "`n检查结果:" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray

$hasIssues = $false
foreach ($issue in $issues) {
Write-Host "[$($issue.Item)] $($issue.Status)" -ForegroundColor $(if ($issue.Status -match "✓") { "Green" } elseif ($issue.Status -match "⚠️") { "Yellow" } else { "Red" })
if ($issue.Solution) {
Write-Host " 解决方案: $($issue.Solution)" -ForegroundColor Gray
$hasIssues = $true
}
}

if ($hasIssues) {
Write-Host "`n建议:解决上述问题后重试" -ForegroundColor Yellow
} else {
Write-Host "`n✓ 所有检查通过,可以继续操作" -ForegroundColor Green
}

日志文件分析

dgreadiness工具执行后会生成日志文件,可用于问题诊断:

# 日志文件分析脚本
Write-Host "dgreadiness日志文件分析" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray

# 日志目录
$logDir = "C:\DGLogs"

if (Test-Path $logDir) {
# 获取最新的日志文件
$logFiles = Get-ChildItem -Path $logDir -Filter "*.log" | Sort-Object LastWriteTime -Descending

if ($logFiles.Count -gt 0) {
$latestLog = $logFiles[0]
Write-Host "最新日志文件: $($latestLog.Name)" -ForegroundColor Green
Write-Host "创建时间: $($latestLog.LastWriteTime)" -ForegroundColor Yellow
Write-Host "文件大小: $([math]::Round($latestLog.Length / 1KB, 2)) KB" -ForegroundColor Yellow
Write-Host ""

# 分析日志内容
Write-Host "日志内容分析:" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Gray

$logContent = Get-Content $latestLog.FullName -Raw

# 查找错误信息
$errors = [regex]::Matches($logContent, "Error|Failed|Exception|警告")
if ($errors.Count -gt 0) {
Write-Host "`n发现 $($errors.Count) 个错误/警告:" -ForegroundColor Red

# 提取错误行
$logLines = Get-Content $latestLog.FullName
foreach ($line in $logLines) {
if ($line -match "Error|Failed|Exception|警告") {
Write-Host " $line" -ForegroundColor Red
}
}
} else {
Write-Host "`n✓ 未发现错误信息" -ForegroundColor Green
}

# 查找关键操作
Write-Host "`n关键操作:" -ForegroundColor Cyan
$keyOperations = @("Disable", "Enable", "HVCI", "VBS", "Device Guard", "Credential Guard")
foreach ($op in $keyOperations) {
if ($logContent -match $op) {
Write-Host " - $op" -ForegroundColor White
}
}

# 显示最后50行
Write-Host "`n日志最后50行:" -ForegroundColor Cyan
Get-Content $latestLog.FullName | Select-Object -Last 50 | ForEach-Object {
$color = "White"
if ($_ -match "Error|Failed|Exception") { $color = "Red" }
elseif ($_ -match "Success|Complete|Done") { $color = "Green" }
elseif ($_ -match "Warning|警告") { $color = "Yellow" }
Write-Host $_ -ForegroundColor $color
}

# 导出日志到文件
$analysisPath = "$logDir\Analysis_$(Get-Date -Format 'yyyyMMdd_HHmmss').txt"
$logContent | Out-File -FilePath $analysisPath
Write-Host "`n日志已保存到: $analysisPath" -ForegroundColor Green
} else {
Write-Host "未找到日志文件" -ForegroundColor Yellow
}
} else {
Write-Host "日志目录不存在: $logDir" -ForegroundColor Yellow
Write-Host "请先运行dgreadiness工具" -ForegroundColor Yellow
}

技术支持资源

官方文档资源

资源名称 URL 说明
dgreadiness工具下载 https://www.microsoft.com/en-us/download/details.aspx?id=53337 官方下载页面
Device Guard文档 https://docs.microsoft.com/en-us/windows/security/threat-protection/device-guard/ 官方技术文档

社区支持资源

资源名称 URL 说明
Microsoft Q&A https://docs.microsoft.com/en-us/answers 官方问答社区
Microsoft Tech Community https://techcommunity.microsoft.com/ 技术社区
GitHub - VBS Disabler https://github.com/zainmustafam977/vbs-disabler-windows11 社区维护的工具
VMware兼容性文档 https://docs.vmware.com/en/VMware-Workstation-Pro/ VMware官方文档

紧急联系方式

如果遇到严重问题导致系统无法启动:

  1. 使用Windows恢复环境

    • 重启3次进入恢复环境
    • 选择”疑难解答” → “高级选项”
    • 使用”系统还原”或”启动修复”
  2. 联系Microsoft支持

    • 官方支持热线
    • 在线聊天支持
    • 社区论坛求助
  3. 寻求专业技术支持

    • IT管理员
    • 认证技术专家
    • Microsoft合作伙伴

常见应用场景

场景 是否需要禁用VBS 替代方案
VMware/VirtualBox使用 ✅ 是 暂无完美替代方案
驱动兼容性问题 ✅ 是 更新驱动程序
性能优化 ⚠️ 视情况 通常不需要
特定软件要求 ✅ 是 联系软件供应商
安全测试 ✅ 是 测试完成后重新启用

快速参考命令

# 快速禁用VBS(完整版)
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
Set-Location "C:\Tools\dgreadiness_v3.6"
.\DG_Readiness_Tool_v3.6.ps1 -Disable -AutoReboot

# 快速禁用HVCI(仅内存完整性)
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
Set-Location "C:\Tools\dgreadiness_v3.6"
.\DG_Readiness_Tool_v3.6.ps1 -Disable -HVCI -AutoReboot

# 验证VBS状态
Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard |
Select-Object VirtualizationBasedSecurityStatus, SecurityServicesRunning

# 检查Hyper-V状态
Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object HypervisorPresent

# 重新启用VBS
.\DG_Readiness_Tool_v3.6.ps1 -Enable -AutoReboot

重要提醒

⚠️ 安全警告

  • 禁用VBS会显著降低系统安全性
  • 仅在必要时执行此操作
  • 操作完成后加强其他安全措施
  • 完成任务后建议重新启用

⚠️ 功能影响

  • Windows Sandbox将无法使用
  • WSL2可能受影响
  • 某些Windows Hello功能受限
  • Credential Guard保护失效

⚠️ 操作建议

  • 操作前务必备份
  • 在测试环境先验证
  • 记录所有配置更改
  • 准备恢复方案

附录

A. 相关技术术语表

术语 英文全称 中文说明
VBS Virtualization-Based Security 基于虚拟化的安全
HVCI Hypervisor-Enforced Code Integrity Hypervisor强制代码完整性
HVCI Memory Integrity 内存完整性(用户界面名称)
DG Device Guard 设备防护
CG Credential Guard 凭据保护
VSM Virtual Secure Mode 虚拟安全模式
UEFI Unified Extensible Firmware Interface 统一可扩展固件接口
SLAT Second Level Address Translation 二级地址转换
TPM Trusted Platform Module 可信平台模块
CI Code Integrity 代码完整性
BCD Boot Configuration Data 启动配置数据

B. 系统要求对照表

组件 Windows 10 Windows 11 Windows Server
最低版本 1607 21H2 2016
推荐版本 21H2+ 23H2+ 2019+
内存(最低) 4GB 4GB 4GB
内存(推荐) 8GB+ 8GB+ 8GB+
TPM 1.2+ 2.0+ 2.0+
CPU 64位VT-x/AMD-V 64位VT-x/AMD-V 64位VT-x/AMD-V
SLAT 必需 必需 必需

C. 错误代码速查表

错误代码 错误名称 常见原因 解决方案
0x80070005 ERROR_ACCESS_DENIED 权限不足 以管理员身份运行
0x80070002 ERROR_FILE_NOT_FOUND 文件不存在 检查路径
0x80070490 ERROR_NOT_FOUND 元素未找到 检查驱动兼容性
0x80092004 CRYPT_E_NOT_FOUND 证书未找到 检查Secure Boot
0xC0000022 STATUS_ACCESS_DENIED 访问被拒绝 检查权限和策略
0x000000EF CRITICAL_PROCESS_DIED 关键进程终止 系统修复或还原

D. PowerShell命令速查

# 检查VBS状态
Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard

# 检查Hyper-V状态
Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object HypervisorPresent

# 修改执行策略
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

# 检查管理员权限
([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

# 创建系统还原点
Checkpoint-Computer -Description "Before VBS Disable" -RestorePointType "MODIFY_SETTINGS"

# 查看BCD配置
bcdedit /enum

# 修改BCD
bcdedit /set hypervisorlaunchtype off
bcdedit /set vsmlaunchtype off

# 禁用Windows功能
Disable-WindowsOptionalFeature -Online -FeatureName "Microsoft-Hyper-V-All" -NoRestart

# 查看Windows功能
Get-WindowsOptionalFeature -Online | Where-Object { $_.State -eq "Enabled" }

# 检查服务状态
Get-Service -Name hvboot, HvHost, vmms

# 查看系统信息
systeminfo
msinfo32

# 查看事件日志
Get-WinEvent -FilterHashtable @{LogName='System'; Level=2} -MaxEvents 10

# 检查驱动签名
Get-CimInstance -ClassName Win32_PnPSignedDriver

E. 常用路径和文件位置

dgreadiness工具:
- 默认位置: C:\Tools\dgreadiness_v3.6\
- 主脚本: DG_Readiness_Tool_v3.6.ps1
- 日志目录: C:\DGLogs\

注册表路径:
- Device Guard: HKLM\SYSTEM\CurrentControlSet\Control\DeviceGuard
- LSA: HKLM\SYSTEM\CurrentControlSet\Control\Lsa
- 组策略: HKLM\SOFTWARE\Policies\Microsoft\Windows\Device Guard

系统文件:
- Hyper-V驱动: C:\Windows\System32\drivers\hv*.sys
- SecConfig.efi: EFI分区\EFI\Microsoft\Boot\SecConfig.efi

日志文件:
- 系统日志: C:\Windows\Logs\
- 事件查看器: 事件查看器 → Windows 日志

文档版本: 1.0
最后更新: 2026年3月21日
适用系统: Windows 10 1607+, Windows 11, Windows Server 2016+
工具版本: dgreadiness v3.6


本站点文档仅供技术参考,操作前请确保已充分理解相关风险并做好备份工作。如有疑问,请咨询专业技术人员。