Unpin Start 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # https://superuser.com/a/1442733
  2. #Requires -RunAsAdministrator
  3. $START_MENU_LAYOUT = @"
  4. <LayoutModificationTemplate xmlns:defaultlayout="http://schemas.microsoft.com/Start/2014/FullDefaultLayout" xmlns:start="http://schemas.microsoft.com/Start/2014/StartLayout" Version="1" xmlns:taskbar="http://schemas.microsoft.com/Start/2014/TaskbarLayout" xmlns="http://schemas.microsoft.com/Start/2014/LayoutModification">
  5. <LayoutOptions StartTileGroupCellWidth="6" />
  6. <DefaultLayoutOverride>
  7. <StartLayoutCollection>
  8. <defaultlayout:StartLayout GroupCellWidth="6" />
  9. </StartLayoutCollection>
  10. </DefaultLayoutOverride>
  11. </LayoutModificationTemplate>
  12. "@
  13. $layoutFile="C:\Windows\StartMenuLayout.xml"
  14. #Delete layout file if it already exists
  15. If(Test-Path $layoutFile)
  16. {
  17. Remove-Item $layoutFile
  18. }
  19. #Creates the blank layout file
  20. $START_MENU_LAYOUT | Out-File $layoutFile -Encoding ASCII
  21. $regAliases = @("HKLM", "HKCU")
  22. #Assign the start layout and force it to apply with "LockedStartLayout" at both the machine and user level
  23. foreach ($regAlias in $regAliases){
  24. $basePath = $regAlias + ":\SOFTWARE\Policies\Microsoft\Windows"
  25. $keyPath = $basePath + "\Explorer"
  26. IF(!(Test-Path -Path $keyPath)) {
  27. New-Item -Path $basePath -Name "Explorer"
  28. }
  29. Set-ItemProperty -Path $keyPath -Name "LockedStartLayout" -Value 1
  30. Set-ItemProperty -Path $keyPath -Name "StartLayoutFile" -Value $layoutFile
  31. }
  32. #Restart Explorer, open the start menu (necessary to load the new layout), and give it a few seconds to process
  33. Stop-Process -name explorer
  34. Start-Sleep -s 5
  35. $wshell = New-Object -ComObject wscript.shell; $wshell.SendKeys('^{ESCAPE}')
  36. Start-Sleep -s 5
  37. #Enable the ability to pin items again by disabling "LockedStartLayout"
  38. foreach ($regAlias in $regAliases){
  39. $basePath = $regAlias + ":\SOFTWARE\Policies\Microsoft\Windows"
  40. $keyPath = $basePath + "\Explorer"
  41. Set-ItemProperty -Path $keyPath -Name "LockedStartLayout" -Value 0
  42. }
  43. #Restart Explorer and delete the layout file
  44. Stop-Process -name explorer
  45. # Uncomment the next line to make clean start menu default for all new users
  46. #Import-StartLayout -LayoutPath $layoutFile -MountPath $env:SystemDrive\
  47. Remove-Item $layoutFile