Wednesday, May 7, 2014

Powershell script to customize windows mouse schemes and pointer options

The following post will show a script that can be used to set the windows mouse pointer scheme as well as the pointer option to enable Show location of pointer when I press the CTRL key in the Default user profile.

This script came about after a request I received from a faculty member to make some accessibility changes in one of the labs they were using.  Initially I looked to see if there was a solution in group policy but didn't find one there.  However, I figured it should just be a matter of finding the correct registry keys to make the changes.

After doing some searching I found that the mouse pointer schemes are held in the HKCU\Control Panel\Cursors location in the registry.  I then changed the scheme on a test box and adjusted my script to match the scheme I wanted to distribute.

The setting for the pointer option I wanted to change was located in the HKCU\Control Panel\Desktop\UserPreferencesMask key.  This is a binary key that is responsible for multiple settings.  An example of the default key is 9E 1E 07 80 12 00 00 00.  The highlighted section of the example key shows which value changes when the pointer option for Show location pointer when I press the CTRL key is select.  Once selected the value of that section changed from 1E to 5E.

One quick note about my script is that this script only performs this action on the Default user profile so any new user will receive these changes.  If you want to perform this on a system that may contain existing users you have two choices.

  1. Create a logon script that sets the settings in the HKCU when the user logs in.
  2. Edit the powershell script to first list all user profiles on the system and then do a foreach to mount each profile and apply the appropriate settings.  The benefit of this method is that it can be distributed and applied without a user being logged into the system; however, precautions will need to be taken in those cases where a user is logged into a system and the profile may be locked.

Powershell script to load the Default user profile, change mouse scheme, and enable Show location pointer when I press the CTRL key.

<#
Description: This script will import the Default user hive (ntuser.dat).
Then it will apply registry keys to set the mouse pointer scheme and
enable "Show location of pointer when I press the CTRL key".

Created By: Michael J. Wolf
Date Created: 2014/05/07
#>

#Load Default user hive to HKU\hive
New-PSDrive -PSProvider registry -Root HKEY_USERS -Name HKU
reg load HKU\hive "C:\Users\Default\ntuser.dat"

#Set Mouse Pointer Scheme to Windows Black (extra large)
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name "(Default)" -Value "Windows Black (extra large)" -PropertyType String -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name AppStarting -Value %SystemRoot%\cursors\wait_rl.cur -PropertyType ExpandString -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name Arrow -Value %SystemRoot%\cursors\arrow_rl.cur -PropertyType ExpandString -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name Crosshair -Value %SystemRoot%\cursors\cross_rl.cur -PropertyType ExpandString -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name Hand -Value "" -PropertyType ExpandString -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name Help -Value %SystemRoot%\cursors\help_rl.cur -PropertyType ExpandString -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name IBeam -Value %SystemRoot%\cursors\beam_rl.cur -PropertyType ExpandString -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name No -Value %SystemRoot%\cursors\no_rl.cur -PropertyType ExpandString -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name NWPen -Value %SystemRoot%\cursors\pen_rl.cur -PropertyType ExpandString -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name "Scheme Source" -Value 2 -PropertyType DWord -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name SizeAll -Value %SystemRoot%\cursors\move_rl.cur -PropertyType ExpandString -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name SizeNESW -Value %SystemRoot%\cursors\size1_rl.cur -PropertyType ExpandString -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name SizeNS -Value %SystemRoot%\cursors\size4_rl.cur -PropertyType ExpandString -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name SizeNWSE -Value %SystemRoot%\cursors\size2_rl.cur -PropertyType ExpandString -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name SizeWE -Value %SystemRoot%\cursors\size3_rl.cur -PropertyType ExpandString -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name UpArrow -Value %SystemRoot%\cursors\up_rl.cur -PropertyType ExpandString -Force
New-ItemProperty -Path "HKU:\hive\Control Panel\Cursors" -Name Wait -Value %SystemRoot%\cursors\busy_rl.cur -PropertyType ExpandString -Force

#Enable Pointer Option: Show location of pointer when I press the CTRL key
New-ItemProperty -Path "HKU:\hive\Control Panel\Desktop" -Name UserPreferencesMask -Value  ([byte[]](0x9E,0x5E,0x07,0x80,0x12,0x00,0x00,0x00)) -PropertyType Binary -Force

Start-Sleep -Seconds 2

#Unload Default user hive
reg unload HKU\hive

If you are using SCCM and wish to create a package to distribute this script you can reference my post on Microsoft SCCM 2012: Creating a powershell script package.

Microsoft SCCM 2012: Creating a powershell script package

The following post will show you how to create a SCCM 2012 package that runs a powershell script.

I have referenced this in previous posts but wanted to break this out specifically because I find myself referencing this process in many posts.  My future posts will just reference this process in an effort to keep posts to the point.

Creating the powershell script package

  • In the SCCM Console go to Software Library, Application Management, Packages.  Click on Create Package.
  • Package
    • Name = Powershell Script Package Name
    • Description = Package Description
    • Manufacturer =
    • Language = English
    • Version = Version
    • Check This package contains source files.  Browse to the Source folder that contains the powershell script you created.
    • Next.
  • Program Type
    • Select Standard Program, Next.
    • Standard Program
      • Name = Powershell Script Program Name 
      • Command line = powershell -ExecutionPolicy ByPass -File PowershellScriptName.ps1
      • Startup folder =
      • Run = Normal
      • Program can run = Whether or not a user is logged on
      • Next.
    • Requirements
      • Estimated disk space = Unknown
      • Maximum allowed run time = Unknown
      • Next.
  • Summary.  Next.
  • Close.
Right click on your package and distribute it to your distribution point.  After that you should be ready to go to deploy it to collections or call it from other package like your Java install package as you will see in the next post.