I am trying to pin a shortcut from my desktop to the start menu but it’s giving me a permission error even though I am running the powershell as an administrator. I have tried different verbs such as “Open” and it works perfectly fine, yet it gives me this error on pinning to the start menu.
Below is the code I wrote:
<code>$desktopPath = [System.Environment]::GetFolderPath('Desktop')
$shortcutName = "XAMPP Control Panel.lnk" # Name of the shortcut
$shortcutPath = Join-Path $desktopPath $shortcutName
$Shell = New-Object -ComObject Shell.Application
$Folder = $Shell.Namespace((Get-Item $shortcutPath).DirectoryName)
$Item = $Folder.ParseName((Get-Item $shortcutPath).Name)
$Item.Verbs() | ForEach-Object { Write-Output $_.Name }
$Verb = $Item.Verbs() | Where-Object {$_.Name -eq "&Pin to Start"}
if ($Verb) {
$Verb.DoIt()
Write-Output "Pinned."
} else {
Write-Output "Not Pinned"
}
</code>
<code>$desktopPath = [System.Environment]::GetFolderPath('Desktop')
$shortcutName = "XAMPP Control Panel.lnk" # Name of the shortcut
$shortcutPath = Join-Path $desktopPath $shortcutName
$Shell = New-Object -ComObject Shell.Application
$Folder = $Shell.Namespace((Get-Item $shortcutPath).DirectoryName)
$Item = $Folder.ParseName((Get-Item $shortcutPath).Name)
$Item.Verbs() | ForEach-Object { Write-Output $_.Name }
$Verb = $Item.Verbs() | Where-Object {$_.Name -eq "&Pin to Start"}
if ($Verb) {
$Verb.DoIt()
Write-Output "Pinned."
} else {
Write-Output "Not Pinned"
}
</code>
$desktopPath = [System.Environment]::GetFolderPath('Desktop')
$shortcutName = "XAMPP Control Panel.lnk" # Name of the shortcut
$shortcutPath = Join-Path $desktopPath $shortcutName
$Shell = New-Object -ComObject Shell.Application
$Folder = $Shell.Namespace((Get-Item $shortcutPath).DirectoryName)
$Item = $Folder.ParseName((Get-Item $shortcutPath).Name)
$Item.Verbs() | ForEach-Object { Write-Output $_.Name }
$Verb = $Item.Verbs() | Where-Object {$_.Name -eq "&Pin to Start"}
if ($Verb) {
$Verb.DoIt()
Write-Output "Pinned."
} else {
Write-Output "Not Pinned"
}
Here is an image of the error:
1