Advertisement
Guest User

Powershell script to set Explorer Quick Access Toolbar Items

a guest
Apr 22nd, 2017
2,204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Set Explorer Quick Access Toolbar Items
  2.  
  3. # Make a copy of the following registry entry before running this script
  4. # HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Ribbon
  5.  
  6. # change the order of the lines to change the order the tools are displayed
  7. # delete or comment-out tools you do not want
  8. # uncomment the tools you want
  9. $tools =
  10. @(
  11.     #16128, # Undo
  12.     #16129, # Redo
  13.     #12352, # Delete to trashcan
  14.     12384, # Properties
  15.     12336, # New Folder
  16.     #12357,  # Rename
  17.  
  18.     12301, # Open PowerShell Here
  19.     12303, # Open PowerShell As Administrator Here
  20.     #12290, # Open Command Prompt Here (disabled in v1704)
  21.     #12291, # Open Command Prompt As Administrator Here (disabled in v1704)
  22.     12289, # Open New Explorer Window
  23.     12403, # Invert Selection
  24.     12324, # Copy Path
  25.  
  26.     #13651, # Manage Computer
  27.     #12354, # Peranently Delete
  28.     #16482, # Change Explorer Options
  29.  
  30.     0      # useful so list can be resorted without needing to changing commas on last one
  31. )
  32.  
  33. # Explorer default toolset - needed to prevent crashing, don't edit
  34. $defaultTools = @( 16128, 16129, 12352, 12384, 12336, 12357 )
  35.  
  36. # for safety, die if any error encountered
  37. $ErrorActionPreference = "Stop"
  38.  
  39. # read binary XML from registry
  40. $qatBinary = (Get-ItemProperty HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Ribbon -Name QatItems).QatItems
  41.  
  42. # convert into xml
  43. [xml]$xml = [Text.Encoding]::ASCII.GetString($qatBinary)
  44.  
  45. # save a copy of the current setup
  46. $xml.save("previous explorer qat.xml")
  47. #exit
  48.  
  49. # find controls node
  50. $sharedControls = $xml.CustomUI.ribbon.qat.sharedControls
  51. $controls = $sharedControls.control
  52.  
  53. # make a clone of first tool item (this should never be empty)
  54. $item = $controls[0].Clone()
  55.  
  56. # clear tool list
  57. $sharedControls.RemoveAll()
  58.  
  59. # to prevent explorer from crashing, we need to explicitly add any standard items we aren't using
  60. $item.visible = "false"
  61. $item.argument = "0"
  62. foreach ($tool in $defaultTools)
  63. {
  64.     # skip items we are going to add
  65.     if ($tools.Contains($tool)) { continue }
  66.  
  67.     $newItem = $item.Clone()
  68.     $newItem.idQ = "siq:$tool"
  69.     $sharedControls.AppendChild($newItem) | Out-Null
  70. }
  71.  
  72. # now add the tools we want in the order we want
  73. $item.visible = "true"
  74. $item.argument = "0"
  75. foreach ($tool in $tools)
  76. {
  77.     if ($tool -le 0) { break }
  78.  
  79.     $newItem = $item.Clone()
  80.     $newItem.idQ = "siq:$tool"
  81.     $sharedControls.AppendChild($newItem) | Out-Null
  82. }
  83.  
  84. # convert XML back into binary sequence
  85. $qatBinary = [Text.Encoding]::ASCII.GetBytes($xml.OuterXml)
  86.  
  87. # write binary XML back into registry
  88. New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Ribbon -Name "QatItems" -PropertyType BINARY -Force -Value $qatBinary | Out-Null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement