首页 > 解决方案 > 通过 PowerShell 在 Windows 10 中更改和更新光标的大小

问题描述

我编写了下面的代码来影响(我认为)是负责 Windows 10 中光标和指针大小的唯一 reg 键。

这是我到目前为止的代码(里面有一些额外的评论):

$RegConnect             = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]"CurrentUser", "$env:COMPUTERNAME")
$RegCursorsAccess       = $RegConnect.OpenSubKey("Software\Microsoft\Accessibility", $true)
$RegCursorsControlPanel = $RegConnect.OpenSubKey("Control Panel\Cursors", $true)

# In the code below I'm trying to change the size of the cursor.

$RegCursorsControlPanel.SetValue("CursorBaseSize", 48)
$RegCursorsAccess.SetValue("CursorSize", 3)

$RegCursorsAccess.Close()
$RegConnect.Close()

# This section is where I thought it would update the cursor size.

# Here is where it lists stuff relating to setting and updating any settings changed.
# https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa
    # SPI_SETCURSORS
    # 0x0057
    # Reloads the system cursors. Set the uiParam parameter to zero and the pvParam parameter to NULL.

$CSharpSig = @'
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern bool SystemParametersInfo(
                  uint uiAction,
                  uint uiParam,
                  uint pvParam,
                  uint fWinIni);
'@
$CursorRefresh = Add-Type -MemberDefinition $CSharpSig -Name WinAPICall -Namespace SystemParamInfo -PassThru
$CursorRefresh::SystemParametersInfo(0x0057,0,$null,0)

它将更改注册表中的正确值。

因此,如果我运行此 PowerShell 代码,则易于访问设置中的鼠标大小处于正确值。

光标和指针大小设置

但是游标没有更新。

如何在不注销并重新登录或重新启动机器的情况下强制更新。


以下是一些相关的 MS 链接:

WM_SETTINGCHANGE 消息

SystemParametersInfoA 函数


编辑 - 一些附加信息

如果我从 Sysinternals 运行 Process Monitor并深入挖掘,我可以在堆栈摘要下看到这一点。

这可能会导致比我更有知识的人找到如何更新鼠标大小。

HKCU\Control Panel\Cursors\(Default)部分SettingsHandlers_nt.dll

Sysinternals 进程监视器

这也适用于可访问性部分。Windows.UI.Accessibility.dll

Windows.UI.Accessibility.dll

以下是我在 Process Monitors 过滤器中用于缩小项目范围的设置。

用作过滤器的设置

标签: powershellwinapi

解决方案


因此,在使用作弊引擎对 SystemSettings.exe 进行了一些修改后,我发现了 MS 如何设置光标大小。它最终仍然使用 SystemParametersInfo 但带有一些未记录的参数。尝试以下方法:)

SystemParametersInfo(0x2029, 0, 16, 0x01);

将光标大小设置为 16。是的,您可以低于其最小值 32,一直到 1 :)


推荐阅读