Advertisement
Guest User

Set Cursor.ps1

a guest
Jan 13th, 2022
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #### Settings to Apply
  2. # The cursor scheme to apply (not used if scheme source is Windows Default)
  3. $CursorScheme = ""
  4. # 0 - Windows Default
  5. # 1 - User Scheme
  6. # 2 - System Scheme
  7. $CursorSchemeSource = 0
  8. # The uniform cursor size (default: 32x32 pixels)
  9. $CursorSize = 32
  10.  
  11. #### Modify Registry
  12. Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "(Default)" -Value $CursorScheme
  13. Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "Scheme Source" -Value $CursorSchemeSource
  14. Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name "CursorBaseSize" -Value $CursorSize
  15. $schemeKeys = @(
  16.     "Arrow", # Normal Select
  17.     "Help", # Help Select
  18.     "AppStarting", # Working in Background
  19.     "Wait", # Busy
  20.     "Crosshair", # Precision Select
  21.     "IBeam", # Text Select
  22.     "NWPen", # Handwriting
  23.     "No", # Unavailable
  24.     "SizeNS", # Vertical Resize
  25.     "SizeWE", # Horizontal Resize
  26.     "SizeNWSE", # Diagonal Resize 1
  27.     "SizeNESW", # Diagonal Resize 2
  28.     "SizeAll", # Move
  29.     "UpArrow", # Alternate Select
  30.     "Hand", # Link Select
  31.     "Pin", # Location Select
  32.     "Person" # Person Select
  33. )
  34.  
  35. switch ($CursorSchemeSource) {
  36.     0 {
  37.         $schemeValues = @()
  38.         for ($i=0; $i -lt $schemeKeys.length; $i++) {
  39.             $schemeValues += ""
  40.         }
  41.     }
  42.     1 {
  43.         $schemeValues = (Get-Item -Path "HKCU:\Control Panel\Cursors\Schemes").GetValue(
  44.             $CursorScheme,  # registry key
  45.             $null,   # default value to return if not exist
  46.             'DoNotExpandEnvironmentNames' # options
  47.         ).Split(',')  
  48.     }
  49.    
  50.     2 {
  51.         $schemeValues = (Get-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Control Panel\Cursors\Schemes").GetValue(
  52.             $CursorScheme,  # registry key
  53.             $null,   # default value to return if not exist
  54.             'DoNotExpandEnvironmentNames' # options
  55.         ).Split(',')
  56.      }
  57. }
  58.  
  59. for ($i=0; $i -lt $schemeKeys.length; $i++) {
  60.     Set-ItemProperty -Path "HKCU:\Control Panel\Cursors" -Name $schemeKeys[$i] -Value $schemeValues[$i]
  61. }
  62.  
  63.  
  64. #### Notify Windows of Changes
  65. $SPI_SETCURSORS = 0x0057
  66. $SPI_SETCURSORSIZE = 0x2029 # supposedly undocumented, so i'll give it some name
  67. $SPIF_UPDATEINIFILE = 0x01
  68. $SPIF_SENDCHANGE = 0x02
  69.  
  70. $CSharpSig = @'
  71. [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
  72. public static extern bool SystemParametersInfo(
  73.                  uint uiAction,
  74.                  uint uiParam,
  75.                  uint pvParam,
  76.                  uint fWinIni);
  77. '@
  78. $CursorRefresh = Add-Type -MemberDefinition $CSharpSig -Name WinAPICall -Namespace SystemParamInfo -PassThru
  79.  
  80. $CursorRefresh::SystemParametersInfo($SPI_SETCURSORSIZE, 0, $CursorSize, $SPIF_UPDATEINIFILE);
  81. $CursorRefresh::SystemParametersInfo($SPI_SETCURSORS, 0, 0, $SPIF_UPDATEINIFILE -bor $SPIF_SENDCHANGE);
  82.  
  83. ####
  84. Write-Host "Done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement