# ========================================================= # MAX Windows Toolkit - 管理快捷方式箭头 # ========================================================= $Common = "C:\Setup\windows\lib\common.ps1" if (Test-Path $Common) { . $Common } else { function Write-Header { param([string]$Title) Clear-Host; Write-Host "==== $Title ====" -ForegroundColor Green } function Write-Section { param([string]$Text) Write-Host ""; Write-Host "-- $Text --" -ForegroundColor Magenta } function Write-OK { Write-Host " OK $($args[0])" -ForegroundColor Green } function Write-Warn { Write-Host " !! $($args[0])" -ForegroundColor Yellow } function Write-Err { Write-Host " XX $($args[0])" -ForegroundColor Red } function Write-Info { Write-Host " $($args[0])" -ForegroundColor White } function Write-Muted { Write-Host " $($args[0])" -ForegroundColor DarkGray } function Pause-Max { Write-Host ""; Read-Host "按 Enter 返回..." } function Write-Line { Write-Host "------------------------------" -ForegroundColor DarkGray } function Test-IsAdmin { try { $id = [Security.Principal.WindowsIdentity]::GetCurrent(); $p = New-Object Security.Principal.WindowsPrincipal($id); return $p.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) } catch { return $false } } function Show-AdminWarn { if (-not (Test-IsAdmin)) { Write-Warn "未以管理员身份运行,部分功能可能失败" } } } Show-AdminWarn $ShellIconsPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" $ShellIconsName = "29" function Restart-Explorer { Write-Info "正在重启资源管理器..." try { Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 2 Start-Process explorer.exe Write-OK "资源管理器已重启" } catch { Write-Err "重启资源管理器失败" Write-Muted $_.Exception.Message } } function Clear-IconCache { Write-Info "正在清理图标缓存..." try { Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 1 $IconCacheFiles = @( "$env:LocalAppData\IconCache.db", "$env:LocalAppData\Microsoft\Windows\Explorer\iconcache_*.db", "$env:LocalAppData\Microsoft\Windows\Explorer\thumbcache_*.db" ) foreach ($Item in $IconCacheFiles) { Remove-Item $Item -Force -ErrorAction SilentlyContinue } Start-Process explorer.exe Write-OK "图标缓存已清理" } catch { Write-Warn "清理图标缓存失败" Write-Muted $_.Exception.Message } } function Remove-ShortcutArrow { Write-Header "移除桌面快捷方式箭头" if (-not (Test-IsAdmin)) { Write-Warn "请以管理员身份运行 PowerShell" return } Write-Info "此操作将移除快捷方式箭头覆盖层(Shell Icons 值 29)" Write-Info "注册表路径:" Write-Muted $ShellIconsPath Write-Warn "需要重启资源管理器" Write-Line $Confirm = Read-Host " 继续?输入 YES 确认" if ($Confirm -ne "YES") { Write-Warn "已取消" return } try { if (-not (Test-Path $ShellIconsPath)) { New-Item -Path $ShellIconsPath -Force | Out-Null } New-ItemProperty ` -Path $ShellIconsPath ` -Name $ShellIconsName ` -Value "%windir%\System32\shell32.dll,-50" ` -PropertyType String ` -Force | Out-Null Write-OK "快捷方式箭头已移除" Write-Warn "如果图标未刷新,请清理图标缓存或重启 Windows" Restart-Explorer } catch { Write-Err "移除快捷方式箭头失败" Write-Muted $_.Exception.Message } } function Restore-ShortcutArrow { Write-Header "恢复桌面快捷方式箭头" if (-not (Test-IsAdmin)) { Write-Warn "请以管理员身份运行 PowerShell" return } Write-Info "此操作将恢复 Windows 默认的快捷方式箭头覆盖层" Write-Info "将删除以下注册表值:" Write-Muted "$ShellIconsPath\$ShellIconsName" Write-Warn "需要重启资源管理器" Write-Line $Confirm = Read-Host " 继续?输入 YES 确认" if ($Confirm -ne "YES") { Write-Warn "已取消" return } try { if (Test-Path $ShellIconsPath) { Remove-ItemProperty ` -Path $ShellIconsPath ` -Name $ShellIconsName ` -Force ` -ErrorAction SilentlyContinue Write-OK "快捷方式箭头已恢复" } else { Write-Warn "Shell Icons 注册表路径不存在,应已为默认箭头状态" } Restart-Explorer } catch { Write-Err "恢复快捷方式箭头失败" Write-Muted $_.Exception.Message } } function Show-ShortcutArrowStatus { Write-Header "快捷方式箭头状态" Write-Info "注册表路径:" Write-Muted $ShellIconsPath try { if (Test-Path $ShellIconsPath) { $Value = Get-ItemProperty -Path $ShellIconsPath -Name $ShellIconsName -ErrorAction SilentlyContinue if ($Value -and $Value.$ShellIconsName) { Write-Warn "状态:快捷方式箭头可能已被移除或自定义" Write-Info "值: $($Value.$ShellIconsName)" } else { Write-OK "状态:默认 Windows 快捷方式箭头" } } else { Write-OK "状态:默认 Windows 快捷方式箭头" } } catch { Write-Warn "无法读取快捷方式箭头状态" Write-Muted $_.Exception.Message } } function Show-ShortcutArrowTips { Write-Header "快捷方式箭头使用提示" Write-Info "此工具控制桌面快捷方式箭头覆盖层" Write-Info "" Write-Warn "移除快捷方式箭头:" Write-Muted "设置 HKLM Explorer Shell Icons 值 29" Write-Muted "重启资源管理器" Write-Info "" Write-Warn "恢复快捷方式箭头:" Write-Muted "删除 Shell Icons 值 29" Write-Muted "重启资源管理器" Write-Info "" Write-Warn "如果图标未刷新:" Write-Muted "使用选项 4 清理图标缓存" Write-Muted "或重启 Windows" } :arrowLoop while ($true) { Write-Header "管理桌面快捷方式箭头" Write-Info "可用操作:" Write-Info "1. 移除快捷方式箭头" Write-Info "2. 恢复快捷方式箭头" Write-Info "3. 查看快捷方式箭头状态" Write-Info "4. 清理图标缓存并重启资源管理器" Write-Info "5. 重启资源管理器" Write-Info "6. 使用提示" Write-Info "0. 退出" Write-Line $Choice = Read-Host " 请选择" switch ($Choice.Trim()) { "1" { Remove-ShortcutArrow Pause-Max } "2" { Restore-ShortcutArrow Pause-Max } "3" { Show-ShortcutArrowStatus Pause-Max } "4" { Clear-IconCache Pause-Max } "5" { Restart-Explorer Pause-Max } "6" { Show-ShortcutArrowTips Pause-Max } "0" { break :arrowLoop } default { Write-Err "无效选项" Pause-Max } } }