From c9d27e3ae2bbb0c5a8a7ba958d9f74cb706345a9 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 25 Jan 2021 11:51:49 -0600 Subject: [PATCH] Fix script not removing all the tiles --- Individual Scripts/Unpin Start | 67 +++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/Individual Scripts/Unpin Start b/Individual Scripts/Unpin Start index 0ea0b42..b70c769 100644 --- a/Individual Scripts/Unpin Start +++ b/Individual Scripts/Unpin Start @@ -1,9 +1,58 @@ -#https://superuser.com/questions/1068382/how-to-remove-all-the-tiles-in-the-windows-10-start-menu -#Unpins all tiles from the Start Menu - Write-Output "Unpinning all tiles from the start menu" - (New-Object -Com Shell.Application). - NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}'). - Items() | - %{ $_.Verbs() } | - ?{$_.Name -match 'Un.*pin from Start'} | - %{$_.DoIt()} \ No newline at end of file +# https://superuser.com/a/1442733 +#Requires -RunAsAdministrator + +$START_MENU_LAYOUT = @" + + + + + + + + +"@ + +$layoutFile="C:\Windows\StartMenuLayout.xml" + +#Delete layout file if it already exists +If(Test-Path $layoutFile) +{ + Remove-Item $layoutFile +} + +#Creates the blank layout file +$START_MENU_LAYOUT | Out-File $layoutFile -Encoding ASCII + +$regAliases = @("HKLM", "HKCU") + +#Assign the start layout and force it to apply with "LockedStartLayout" at both the machine and user level +foreach ($regAlias in $regAliases){ + $basePath = $regAlias + ":\SOFTWARE\Policies\Microsoft\Windows" + $keyPath = $basePath + "\Explorer" + IF(!(Test-Path -Path $keyPath)) { + New-Item -Path $basePath -Name "Explorer" + } + Set-ItemProperty -Path $keyPath -Name "LockedStartLayout" -Value 1 + Set-ItemProperty -Path $keyPath -Name "StartLayoutFile" -Value $layoutFile +} + +#Restart Explorer, open the start menu (necessary to load the new layout), and give it a few seconds to process +Stop-Process -name explorer +Start-Sleep -s 5 +$wshell = New-Object -ComObject wscript.shell; $wshell.SendKeys('^{ESCAPE}') +Start-Sleep -s 5 + +#Enable the ability to pin items again by disabling "LockedStartLayout" +foreach ($regAlias in $regAliases){ + $basePath = $regAlias + ":\SOFTWARE\Policies\Microsoft\Windows" + $keyPath = $basePath + "\Explorer" + Set-ItemProperty -Path $keyPath -Name "LockedStartLayout" -Value 0 +} + +#Restart Explorer and delete the layout file +Stop-Process -name explorer + +# Uncomment the next line to make clean start menu default for all new users +#Import-StartLayout -LayoutPath $layoutFile -MountPath $env:SystemDrive\ + +Remove-Item $layoutFile