【问题标题】:Changing Windows 10 cursor icon with Powershell without reseting使用 Powershell 更改 Windows 10 光标图标而不重置
【发布时间】:2022-02-12 15:56:56
【问题描述】:
我正在为 Windows 制作一个启动脚本,并且一直想要更改我的光标图标。但是,我想在不重置计算机并通过 powershell 的情况下进行操作。
Set-ItemProperty -Path "HKCU:\Control Panel\Cursors\Arrow" -Value
"F:\nutty-squirrels\callmezippy_squirrelUnavailble.cur"
我知道可以在不使用 GUI 重置的情况下更改光标图标,但我似乎无法使用脚本让它工作,因为 regedit 不会更新光标(或者,至少它没有通过我的测试。)
我认为重置某些进程会允许光标更改,但我不知道该进程是什么。如果有人有任何想法,那将是一个很大的帮助!
【问题讨论】:
标签:
powershell
windows-10
registry
mouse-cursor
regedit
【解决方案1】:
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()