Skip to content

Commit

Permalink
(GH-264) Do not fail if shortcut creation fails
Browse files Browse the repository at this point in the history
When creating shortcuts, consider that gravy and do not fail if the
function fails. It can fail for several reasons, including attempting
to create a Desktop shortcut for LocalSystem (which doesn't have a user
profile).
  • Loading branch information
ferventcoder committed May 2, 2015
1 parent 6de64c8 commit 902725d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ param(
$lnk.WorkingDirectory = $workingDirectory
$lnk.Save()

Write-Debug "Desktop Shortcut created pointing at `'$targetFilePath`'."
Write-Host "Desktop Shortcut created pointing at `'$targetFilePath`'."

}
catch {
throw $_.Exception
Write-Warning "Unable to create desktop link. Error captured was $($_.Exception.Message)."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ try {
Write-Host "'$menuKey' explorer menu item has been created"
}
catch {
$errorMessage = "'$menuKey' explorer menu item was not created $($_.Exception.Message)"
Write-Error $errorMessage
throw $errorMessage
$errorMessage = "'$menuKey' explorer menu item was not created - $($_.Exception.Message)"
Write-Warning $errorMessage
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,28 @@ param(

Write-Debug "Running 'Install-ChocolateyPinnedTaskBarItem' with targetFilePath:`'$targetFilePath`'";

if (test-path($targetFilePath)) {
$verb = "Pin To Taskbar"
$path= split-path $targetFilePath
$shell=new-object -com "Shell.Application"
$folder=$shell.Namespace($path)
$item = $folder.Parsename((split-path $targetFilePath -leaf))
$itemVerb = $item.Verbs() | ? {$_.Name.Replace("&","") -eq $verb}
if($itemVerb -eq $null){
Write-Host "TaskBar verb not found for $item. It may have already been pinned"
} else {
$itemVerb.DoIt()
}
Write-Host "`'$targetFilePath`' has been pinned to the task bar on your desktop"
} else {
$errorMessage = "`'$targetFilePath`' does not exist, not able to pin to task bar"
}
if($errorMessage){
Write-Error $errorMessage
throw $errorMessage
try{
if (test-path($targetFilePath)) {
$verb = "Pin To Taskbar"
$path= split-path $targetFilePath
$shell=new-object -com "Shell.Application"
$folder=$shell.Namespace($path)
$item = $folder.Parsename((split-path $targetFilePath -leaf))
$itemVerb = $item.Verbs() | ? {$_.Name.Replace("&","") -eq $verb}
if($itemVerb -eq $null){
Write-Host "TaskBar verb not found for $item. It may have already been pinned"
} else {
$itemVerb.DoIt()
}
Write-Host "`'$targetFilePath`' has been pinned to the task bar on your desktop"
} else {
$errorMessage = "`'$targetFilePath`' does not exist, not able to pin to task bar"
}

if ($errorMessage) {
Write-Warning $errorMessage
}
} catch {
Write-Warning "Unable to create pin. Error captured was $($_.Exception.Message)."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ directoy, an icon to be used for the shortcut, along with a description and argu
Write-Debug "Shortcut created."
}
catch {
throw $_.Exception
Write-Warning "Unable to create shortcut. Error captured was $($_.Exception.Message)."
}
}

0 comments on commit 902725d

Please sign in to comment.