删除Win11右键菜单的打开方式中建议的项目或更多项目的软件项

以百度云盘为例

一:问题现象:

在这里插入图片描述
在这里插入图片描述
注:这篇文章和\shellex\ContextMenuHandlers\这个右键菜单没有任何关系

二:解决方法

计算机\HKEY_USERS\S-1-5-21-*\Software\Classes\Applications注册表路径里删除BaiduNetdisk.open

或者运行ps1脚本
文件名:Remove-BaiduNetdiskRegistryPaths.ps1

# 加载 Windows Forms 程序集
Add-Type -AssemblyName System.Windows.Forms

# 定义目标路径的相对部分(未知的 SID 部分将动态枚举)
$relativePath = "Software\Classes\Applications\BaiduNetdisk.open"

# 获取当前加载的 HKEY_USERS 子项(即有效的用户 Hive)
try {
    $userKeys = Get-ChildItem -Path "Registry::HKEY_USERS" -ErrorAction Stop | Where-Object { $_.PSChildName -ne "_Classes" } # 排除 _Classes(可选)
} catch {
    [System.Windows.Forms.MessageBox]::Show("无法访问 HKEY_USERS 注册表路径,请以管理员权限运行脚本。", "错误", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
    exit
}

# 使用 [System.Collections.Generic.List[string]] 存储找到的路径
$foundPaths = [System.Collections.Generic.List[string]]::new()

# 遍历每个用户 Hive
foreach ($userKey in $userKeys) {
    $userSid = $userKey.PSChildName
    $fullPath = "Registry::HKEY_USERS\$userSid\$relativePath"

    # 检查目标路径是否存在
    if (Test-Path -Path $fullPath) {
        $foundPaths.Add($fullPath) # 动态添加路径到 List
    }
}

# 输出找到的路径(可选,仅用于调试)
if ($foundPaths.Count -gt 0) {
    Write-Host "找到以下目标路径:" -ForegroundColor Green
    $foundPaths | ForEach-Object { Write-Host $_ }

    # 构建消息框内容
    $message = "找到以下目标路径:`n" + ($foundPaths -join "`n") + "`n`n是否删除这些路径?"

    # 显示消息框并获取用户选择
    $result = [System.Windows.Forms.MessageBox]::Show($message, "确认删除", [System.Windows.Forms.MessageBoxButtons]::YesNo, [System.Windows.Forms.MessageBoxIcon]::Question)

    if ($result -eq [System.Windows.Forms.DialogResult]::Yes) {
        foreach ($path in $foundPaths) {
            try {
                Remove-Item -Path $path -Recurse -Force -ErrorAction Stop
                Write-Host "已删除: $path" -ForegroundColor Green
            } catch {
                Write-Host "无法删除: $path. 错误: $_" -ForegroundColor Red
            }
        }
    } else {
        Write-Host "未删除任何路径。" -ForegroundColor Yellow
    }
} else {
    [System.Windows.Forms.MessageBox]::Show("未找到任何目标路径: HKEY_USERS\*\$relativePath", "信息", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
}

Write-Host "按回车键退出..."
Read-Host






1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值