# 修复鼠标指针被替换成锯齿单色光标的问题
# 用法: 右键此文件 -> "使用 PowerShell 运行"
# 原理: 从注册表方案读取系统自带光标文件, 用 SetSystemCursor 直接装回各个指针槽
# 注意: 不要用 SystemParametersInfo(SPI_SETCURSORS) 重载——在这台机器上它会生成单色光标
$map = [ordered]@{
'Arrow' = 32512 # OCR_ARROW
'AppStarting' = 32650 # OCR_APPSTARTING
'Wait' = 32514 # OCR_WAIT
'No' = 32648 # OCR_NO
'SizeAll' = 32646 # OCR_SIZEALL
'SizeNESW' = 32643 # OCR_SIZENESW
'SizeNS' = 32645 # OCR_SIZENS
'SizeNWSE' = 32642 # OCR_SIZENWSE
'SizeWE' = 32644 # OCR_SIZEWE
'UpArrow' = 32516 # OCR_UP
'Hand' = 32649 # OCR_HAND
'Help' = 32651 # OCR_HELP
}
Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
public class CursorRestore {
[DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr LoadCursorFromFile(string f);
[DllImport("user32.dll")] public static extern bool SetSystemCursor(IntPtr hcur, uint id);
}
'@
$fixed = 0
foreach ($k in $map.Keys) {
$v = (Get-ItemProperty 'HKCU:\Control Panel\Cursors' -Name $k -ErrorAction SilentlyContinue).$k
if (-not $v) { continue }
$path = [Environment]::ExpandEnvironmentVariables($v)
if (-not (Test-Path $path)) { continue }
$h = [CursorRestore]::LoadCursorFromFile($path)
if ($h -ne [IntPtr]::Zero -and [CursorRestore]::SetSystemCursor($h, [uint32]$map[$k])) {
Write-Output ("OK {0} <- {1}" -f $k, $path)
$fixed++
} else {
Write-Output ("FAIL {0} <- {1}" -f $k, $path)
}
}
Write-Output ("done, {0} cursors restored" -f $fixed)