在不重置的情况下使用 Powershell 更改 Windows 10 光标图标

Changing Windows 10 cursor icon with Powershell without reseting

我正在为 Windows 制作启动脚本,并且一直想更改我的光标图标。但是,我想在不重置计算机并通过 powershell 的情况下进行。

Set-ItemProperty -Path "HKCU:\Control Panel\Cursors\Arrow" -Value "F:\nutty-squirrels\callmezippy_squirrelUnavailble.cur"

我知道可以使用 GUI 在不重置的情况下更改光标图标,但我似乎无法使用脚本让它工作,因为 regedit 不更新光标(或者,至少,它没有'通过我的测试。)

我在想重置一些进程会允许光标发生变化,但我不知道那个进程是什么。如果有人有任何想法,那将是一个很大的帮助!

Set-ItemProperty 调用缺少 -Name 参数,您需要调用 WinAPI 函数 SystemParametersInfo 来通知系统设置更改:

# Define a C# class for calling WinAPI.
Add-Type -TypeDefinition @'
public class SysParamsInfo {
    [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
    public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint pvParam, uint fWinIni);
    
    const int SPI_SETCURSORS = 0x0057;
    const int SPIF_UPDATEINIFILE = 0x01;
    const int SPIF_SENDCHANGE = 0x02;

    public static void CursorHasChanged() {
        SystemParametersInfo(SPI_SETCURSORS, 0, 0, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
    }
}
'@

# Change the cursor
Set-ItemProperty -Path 'HKCU:\Control Panel\Cursors' -Name 'Arrow' -Value '%SystemRoot%\cursors\aero_arrow_xl.cur'

# Notify the system about settings change by calling the C# code
[SysParamsInfo]::CursorHasChanged()