@@ -84,6 +84,9 @@ foreach ($entry in $regTaskbar.GetEnumerator()) {
8484$taskBarLocation = ' Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar'
8585$rootKey = ' SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband'
8686
87+ Stop-Process - Name explorer - Force - ErrorAction SilentlyContinue
88+ Start-Sleep - Milliseconds 500
89+
8790# Clearing taskbar, copying the shortcut, setting registry
8891foreach ($userKey in (Get-RegUserPaths - NoDefault).PsPath) {
8992 $sid = Split-Path $userKey - Leaf
@@ -93,17 +96,22 @@ foreach ($userKey in (Get-RegUserPaths -NoDefault).PsPath) {
9396 Write-Error " Couldn't find AppData value for $sid !"
9497 } else {
9598 Write-Title " Setting '$Browser ' taskbar shortcut for '$sid '..."
96-
9799 Write-Output " Clearing current shortcuts..."
98100 $taskBarAppData = " $appData \$taskBarLocation "
99101 if (Test-Path $taskBarAppData - PathType Leaf) {
100- Write-Output " Deleting TaskBar file..."
102+ Write-Output " Deleting corrupted TaskBar file..."
101103 Remove-Item - Path $taskBarAppData - Force
102104 }
103- Get-ChildItem $taskBarAppData | Remove-Item - Force - Recurse
105+ if (! (Test-Path $taskBarAppData - PathType Container)) {
106+ Write-Output " Creating TaskBar folder..."
107+ New-Item - Path $taskBarAppData - ItemType Directory - Force | Out-Null
108+ } else {
109+ Get-ChildItem $taskBarAppData | Remove-Item - Force - Recurse
110+ }
104111
105112 Write-Output " Adding new shortcuts..."
106- Copy-Item - Path " $tmp \*" - Destination $taskBarAppData - Force
113+ # make sure its a folder with a backslash
114+ Copy-Item - Path " $tmp \*" - Destination " $taskBarAppData \" - Force
107115
108116 Write-Output " Changing in Registry..."
109117 $key = " $ ( Convert-Path $userKey ) \$rootKey "
@@ -112,4 +120,5 @@ foreach ($userKey in (Get-RegUserPaths -NoDefault).PsPath) {
112120 }
113121 }
114122}
115- Stop-Process - Name explorer - Force
123+
124+ Stop-Process - Name explorer - Force - ErrorAction SilentlyContinue
0 commit comments