Anye
Anye
发布于 2025-09-26 / 36 阅读
0
0

全新!Edge 还是卸载不掉?来试试这个!

前言

之前写过一篇 https://www.anye.xyz/archives/IuHBJWtU,今天又试了一下,感觉还是太复杂,无论是进入 PE 还是使用 Live CD 都提高了操作难度,经过时间发现当前版本下 ViVeTool 也不是必须的,那么就写个脚本来一键启用 Edge 的卸载功能吧!

启用卸载功能脚本

右键 开始 按钮,打开 终端管理员 ,复制下面的代码粘贴进去即可。

# ============================================
# 启用卸载功能脚本(含备份)
# ============================================

$jsonPath = "C:\Windows\System32\IntegratedServicesRegionPolicySet.json"
$backupPath = "C:\Windows\System32\IntegratedServicesRegionPolicySet.json.bak"

# -------------------------------
# 1. 检查管理员权限
# -------------------------------
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
    Write-Error "请以管理员身份运行此 PowerShell"
    exit
}

# -------------------------------
# 2. 取得文件所有权
# -------------------------------
Write-Host "获取文件所有权..."
takeown /f $jsonPath
icacls $jsonPath /grant administrators:F

# -------------------------------
# 3. 备份原文件
# -------------------------------
Write-Host "备份原文件到 $backupPath"
$backupDir = Split-Path $backupPath
if (-not (Test-Path $backupDir)) { New-Item -ItemType Directory -Path $backupDir -Force }
Copy-Item -Path $jsonPath -Destination $backupPath -Force

# -------------------------------
# 4. 读取 JSON 并修改 policies 数组
# -------------------------------
Write-Host "读取并修改 JSON 文件..."
$jsonContent = Get-Content $jsonPath -Raw | ConvertFrom-Json

# 从注册表获取当前地理位置代码
$geoCode = (Get-ItemProperty -Path 'Registry::HKEY_USERS\.DEFAULT\Control Panel\International\Geo' -Name Name).Name
Write-Host "当前注册表 Geo 地区代码:$geoCode"

# 遍历 policies 数组
foreach ($policy in $jsonContent.policies) {
    if ($policy.'$comment' -eq 'Edge is uninstallable.') {
        # 修改 defaultState
        $policy.defaultState = 'enabled'

        # 修改 enabled 数组,加入注册表获取的地区代码
        $enabledArray = $policy.conditions.region.enabled
        if (-not ($enabledArray -contains $geoCode)) {
            $enabledArray = @($geoCode) + $enabledArray
        }
        $policy.conditions.region.enabled = $enabledArray

        Write-Host "修改完成:$($policy.'$comment')"
    }
}

# 保存回文件
$jsonContent | ConvertTo-Json -Depth 10 | Set-Content $jsonPath -Encoding UTF8

# -------------------------------
# 5. 恢复 TrustedInstaller 权限
# -------------------------------
Write-Host "恢复 TrustedInstaller 权限..."
icacls $jsonPath /setowner "NT SERVICE\TrustedInstaller"
icacls $jsonPath /grant:r "NT SERVICE\TrustedInstaller:(F)" /inheritance:e

Write-Host "操作完成,原文件已备份到 $backupPath"

# -------------------------------
# 6. 修改注册表,允许 Edge 可卸载
# -------------------------------
Write-Host "修改注册表:允许 Microsoft Edge 可卸载..."
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge" /v NoRemove /t REG_DWORD /d 0 /f

执行结束后重启电脑,就可以直接在控制面板或者是 Edge 右键卸载亦或是其他工具中正常卸载 Edge 了!

(可选)恢复备份脚本

这一步非必须,对系统不会造成实质性影响,可选恢复原 IntegratedServicesRegionPolicySet.json 配置文件来寻求心理安慰。

# ============================================
# 恢复 IntegratedServicesRegionPolicySet.json 备份脚本
# ============================================

# 原文件路径
$jsonPath = "C:\Windows\System32\IntegratedServicesRegionPolicySet.json"
# 备份文件路径
$backupPath = "C:\Windows\System32\IntegratedServicesRegionPolicySet.json.bak"

# -------------------------------
# 1. 检查管理员权限
# -------------------------------
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
    Write-Error "请以管理员身份运行此 PowerShell"
    exit
}

# -------------------------------
# 2. 取得文件所有权(防止拒绝访问)
# -------------------------------
Write-Host "获取文件所有权..."
takeown /f $jsonPath
icacls $jsonPath /grant administrators:F

# -------------------------------
# 3. 恢复备份文件
# -------------------------------
if (Test-Path $backupPath) {
    Write-Host "恢复备份文件..."
    Copy-Item -Path $backupPath -Destination $jsonPath -Force
    Write-Host "备份文件已恢复到 $jsonPath"

    # 删除备份文件
    Remove-Item -Path $backupPath -Force
    Write-Host "备份文件已删除:$backupPath"
} else {
    Write-Error "备份文件不存在:$backupPath"
    exit
}

# -------------------------------
# 4. 恢复 TrustedInstaller 权限
# -------------------------------
Write-Host "恢复 TrustedInstaller 权限..."
icacls $jsonPath /setowner "NT SERVICE\TrustedInstaller"
icacls $jsonPath /grant:r "NT SERVICE\TrustedInstaller:(F)" /inheritance:e

Write-Host "操作完成,权限已恢复为 TrustedInstaller"

后记

大哥们,球球别问我卸载了 Edge 用什么浏览器了~


评论