以百度云盘为例
一:问题现象:
注:这篇文章和\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