Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change and update the size of the cursor in Windows 10 via PowerShell

I've written the code below to affect (what I think) are the only reg keys responsible for the size of the cursor and pointer in Windows 10.

Here's the code I have so far (Some additional comments within):

$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)

It will change the correct values in the registry.

So if I run this PowerShell code the mouse size in the ease of access setting is at the correct value.

cursor and pointer size setting

But the cursor doesn't update.

How is it possible to force the update without logging out and back in or restarting the machine.


Here are some related MS links:

WM_SETTINGCHANGE message

SystemParametersInfoA function


EDIT - Some additional info

If I run Process Monitor from Sysinternals and dig deep in there I can see this under the stack summary.

This may lead someone more knowledgeable than me to find how to update the mouse size.

The HKCU\Control Panel\Cursors\(Default) section SettingsHandlers_nt.dll

Sysinternals Process Monitor

And this also for the accessibility section. Windows.UI.Accessibility.dll

Windows.UI.Accessibility.dll

Here are the settings I used in Process Monitors filter to narrow down the items.

Settings used as the filter

like image 804
Ste Avatar asked Feb 06 '20 22:02

Ste


People also ask

How do I resize the cursor in Windows 10?

Open the Settings app. Select Ease of Access, and then Cursor and Pointer, by using your mouse or by tabbing and arrowing through the options. Move the top slider (either by mouse or again by tabbing and arrowing) to adjust the size, and use the buttons below to change the color. Enjoy your large cursor!

How do you resize cursor?

button, click Control Panel, click Ease of Access, click Ease of Access Center, and then click Make the mouse easier to use. Select the options that you want to use: Change the color and size of mouse pointers. You can use these options to make the mouse pointer larger, or change the color to make it easier to see.


1 Answers

So after a bit of hacking about SystemSettings.exe with cheat engine I found how MS sets the cursor size. It ends up still using SystemParametersInfo but with some undocumented arguments. Try the following :)

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

to set a cursor size of 16. yup you can go below their minimum of 32, all the way down to 1 :)

like image 134
HaPpY Avatar answered Oct 18 '22 16:10

HaPpY