To Turn On or Off Show Pointer Location with CTRL Key using PowerShell:
Save this file to your computer as Set-ShowPointerLocation.ps1
Code:
# Set-ShowPointerLocation.ps1
# Turn On or Off "Show Pointer Location when <Ctrl> Key is pressed".
# Parameters:
# $UserKey: Registry key to modify (HKCU or HKU\(SID) or HKU\TempHive)
# $Off: If specified, "Show Pointer Location when <Ctrl> Key is pressed" will be turned off.
# If not secified, "Show Pointer Location when <Ctrl> Key is pressed" will be turned on.
param(
[string]$UserKey = "HKCU",
[switch]$Off
)
#Which bit to toggle in which byte
$Bit = 0x40
$B = 1
$UserPreferencesMask = (Get-ItemProperty "Registry::$($UserKey)\Control Panel\Desktop" -Name "UserPreferencesMask").UserPreferencesMask
If ($UserPreferencesMask -eq $null){
Write-Error "Cannot find $($UserKey)\Control Panel\Desktop: UserPreferencesMask"
exit 2}
# Make a copy of $UserPreferencesMask for comparison
$NewMask = $UserPreferencesMask
# Toggle the "Show pointer location" bit
if ($Off) {$NewMask[$B] = $NewMask[$B] -band -bnot $Bit}
else {$NewMask[$B] = $NewMask[$B] -bor $Bit}
if ($NewMask -ne $UserPreferencesMask) {Set-ItemProperty "Registry::$($UserKey)\Control Panel\Desktop" -Name "UserPreferencesMask" -Value $NewMask}
Exit $error.count
Use one of the following depending on what you want to do:
To turn it ON for the current user from the GUI, just double-click the Set-ShowPointerLocation.ps1 file.
To turn it ON for the current user from the command line or batch file,
Code:
PowerShell -ExecutionPolicy Bypass -file "Set-ShowPointerLocation.ps1"
To turn it OFF for the current user,
Code:
PowerShell -ExecutionPolicy Bypass -file "Set-ShowPointerLocation.ps1" -Off
To turn it ON for another user in HKEY_USERS,
Code:
PowerShell -ExecutionPolicy Bypass -file "Set-ShowPointerLocation.ps1" HKEY_USERS\(sid)
To turn it OFF for the another user in HKEY_USERS,
Code:
PowerShell -ExecutionPolicy Bypass -file "Set-ShowPointerLocation.ps1" HKEY_USERS\(sid) -Off
To turn it ON for another user in the USERS directory,
Code:
FOR /F "tokens=2*" %%P IN ('REG QUERY "HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList" /V "ProfilesDirectory" ^| find /i "REG_"') DO CALL set ProfPath=%%Q
REG LOAD HKU\TempHive "%ProfPath%\(username)\ntuser.dat" 2>NUL: && (
PowerShell -ExecutionPolicy Bypass -file "Set-ShowPointerLocation.ps1" HKU\TempHive
REG UNLOAD HKU\TempHive )
To turn it OFF for the another user in the USERS directory,
Code:
FOR /F "tokens=2*" %%P IN ('REG QUERY "HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList" /V "ProfilesDirectory" ^| find /i "REG_"') DO CALL set ProfPath=%%Q
REG LOAD HKU\TempHive "%ProfPath%\(username)\ntuser.dat" 2>NUL: && (
PowerShell -ExecutionPolicy Bypass -file "Set-ShowPointerLocation.ps1" HKU\TempHive -Off
REG UNLOAD HKU\TempHive )
After running this, you (or the user you changed in HKEY_USERS) must log off and back on before the change takes effect.
Toggling this setting in Control Panel -> Mouse takes effect immediately so the GUI must be doing something else besides changing the registry value. I haven't found out what else it's doing yet.
Shaun,
1. Please add "Download" buttons for this code.
2. Please copy this into the Windows 7, 8 and 11 forums, or provide links there to this one.