Kaseya Community

Script to pin a shortcut into the start menu

This question is not answered

Anyone know how i can write a script that will pin a shortcut into the start menu?

All Replies
  • I know how to do that in windows 10, not sure if it works with win7.

  • Hey Szelic,

    Care to share how you do it in Windows 10?  I'd love to know how.  Also, do you know how to pin to the task bar as well?

    Thanks in advance!

  • Function Set-OSCPin

    {

    <#

    .SYNOPSIS

           Set-OSCPin is an advanced function which can be used to pin a item or more items to the Start menu.

       .DESCRIPTION

           Set-OSCPin is an advanced function which can be used to pin a item or more items to the Start menu.

       .PARAMETER  <Path>

    Specifies a path to one or more locations.

       .EXAMPLE

           C:\PS> Set-OSCPin -Path "C:\Windows"

           Pin "Windows" to the Start menu sucessfully.

    This command shows how to pin the "shutdown.exe" file to the Start menu.

       .EXAMPLE

           C:\PS> Set-OSCPin -Path "C:\Windows","C:\Windows\System32\shutdown.exe"

           Pin "Windows" to the Start menu sucessfully.

           Pin "shutdown.exe" to the Start menu sucessfully.

    This command shows how to pin the "Windows" folder and "shutdown.exe" file to the Start menu.

    #>

       [CmdletBinding()]

       Param

       (

           [Parameter(Mandatory,Position=0)]

           [Alias('p')]

           [String[]]$Path

       )

       $Shell = New-Object -ComObject Shell.Application

    $Desktop = $Shell.NameSpace(0X0)

       $WshShell = New-Object -comObject WScript.Shell

       $Flag=0

       Foreach($itemPath in $Path)

       {

           $itemName = Split-Path -Path $itemPath -Leaf

           #pin application to windows Start menu

           $ItemLnk = $Desktop.ParseName($itemPath)

           $ItemVerbs = $ItemLnk.Verbs()

           Foreach($ItemVerb in $ItemVerbs)

           {

               If($ItemVerb.Name.Replace("&","") -match "Pin to Start")

               {

                   $ItemVerb.DoIt()

                   $Flag=1

               }

           }

           If($Flag=1)

           {

               Write-Host "Pin ""$ItemName"" to the Start menu sucessfully." -ForegroundColor Green

           }

           Else

           {

               Write-Host "The ""$ItemName"" cannot pin to the Start menu." -ForegroundColor Red

           }

       }

    }

    Set-OSCPin -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Outlook 2016.lnk"

    Set-OSCPin -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Word 2016.lnk"

     Set-OSCPin -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Excel 2016.lnk"

     Set-OSCPin -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PowerPoint 2016.lnk"

     Set-OSCPin -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Skype for Business 2016.lnk"

  • Awesome Szelic!  Thank you for this!  

    One side note:  This only allowed me to pin to the Start Menu, not the task bar.  Is there a way to pin to the task bar that you know of?  Thanks again for this!  

  • Here is another way using vbs for pin to Start Menu:

    Const CSIDL_COMMON_PROGRAMS = &H17

    Const CSIDL_PROGRAMS = &H2

    Set objShell = CreateObject("Shell.Application")

    Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)

    strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path

    Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office")

    Set objFolderItem = objFolder.ParseName("Microsoft Word 2010.lnk")

    Set colVerbs = objFolderItem.Verbs

    For Each objVerb in colVerbs

       If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt

    Next

  • Nice!  Thanks James!

  •  I use www.technosys.net/.../pintotaskbar. This is only way it work on windows 10 per my testing. Just copy it via procedure on client pc (I usually copy it to vsa working folder) , then use execute shell command to pin to taskbar.



    Additional info
    [edited by: szelic at 2:30 PM (GMT -7) on Aug 31, 2017]
  • The app isnt working for me. Do you run it differently? See screenshot

    (i'm using calc.exe just as a test)

  • Here's what ultimately worked for me:

    www.tenforums.com/.../21002-how-automatically-cmd-powershell-script-unpin-all-apps-start.html

    I used both suggestions, as it allowed me to pin specific shortcuts as well as Metro Apps:  

    Copy/paste below into your profile.ps1 file under C:\users\<username>\documents\windows powershell\profile.ps1

    Function Set-OSCPin

    {

    <#

    .SYNOPSIS

          Set-OSCPin is an advanced function which can be used to pin a item or more items to the Start menu.

      .DESCRIPTION

          Set-OSCPin is an advanced function which can be used to pin a item or more items to the Start menu.

      .PARAMETER  <Path>

    Specifies a path to one or more locations.

      .EXAMPLE

          C:\PS> Set-OSCPin -Path "C:\Windows"

          Pin "Windows" to the Start menu sucessfully.

    This command shows how to pin the "shutdown.exe" file to the Start menu.

      .EXAMPLE

          C:\PS> Set-OSCPin -Path "C:\Windows","C:\Windows\System32\shutdown.exe"

          Pin "Windows" to the Start menu sucessfully.

          Pin "shutdown.exe" to the Start menu sucessfully.

    This command shows how to pin the "Windows" folder and "shutdown.exe" file to the Start menu.

    #>

      [CmdletBinding()]

      Param

      (

          [Parameter(Mandatory,Position=0)]

          [Alias('p')]

          [String[]]$Path

      )

      $Shell = New-Object -ComObject Shell.Application

    $Desktop = $Shell.NameSpace(0X0)

      $WshShell = New-Object -comObject WScript.Shell

      $Flag=0

      Foreach($itemPath in $Path)

      {

          $itemName = Split-Path -Path $itemPath -Leaf

          #pin application to windows Start menu

          $ItemLnk = $Desktop.ParseName($itemPath)

          $ItemVerbs = $ItemLnk.Verbs()

          Foreach($ItemVerb in $ItemVerbs)

          {

              If($ItemVerb.Name.Replace("&","") -match "Pin to Start")

              {

                  $ItemVerb.DoIt()

                  $Flag=1

              }

          }

          If($Flag=1)

          {

              Write-Host "Pin ""$ItemName"" to the Start menu sucessfully." -ForegroundColor Green

          }

          Else

          {

              Write-Host "The ""$ItemName"" cannot pin to the Start menu." -ForegroundColor Red

          }

      }

    }

    function Pin-App ([string]$appname, [switch]$unpin, [switch]$start, [switch]$taskbar, [string]$path) {

       if ($unpin.IsPresent) {

           $action = "Unpin"

       } else {

           $action = "Pin"

       }

       if (-not $taskbar.IsPresent -and -not $start.IsPresent) {

           Write-Error "Specify -taskbar and/or -start!"

       }

       if ($taskbar.IsPresent) {

           try {

               $exec = $false

               if ($action -eq "Unpin") {

                   ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'Unpin from taskbar'} | %{$_.DoIt(); $exec = $true}

                   if ($exec) {

                       Write "App '$appname' unpinned from Taskbar"

                   } else {

                       if (-not $path -eq "") {

                           Pin-App-by-Path $path -Action $action

                       } else {

                           Write "'$appname' not found or 'Unpin from taskbar' not found on item!"

                       }

                   }

               } else {

                   ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'Pin to taskbar'} | %{$_.DoIt(); $exec = $true}

                   if ($exec) {

                       Write "App '$appname' pinned to Taskbar"

                   } else {

                       if (-not $path -eq "") {

                           Pin-App-by-Path $path -Action $action

                       } else {

                           Write "'$appname' not found or 'Pin to taskbar' not found on item!"

                       }

                   }

               }

           } catch {

               Write-Error "Error Pinning/Unpinning $appname to/from taskbar!"

           }

       }

       if ($start.IsPresent) {

           try {

               $exec = $false

               if ($action -eq "Unpin") {

                   ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'Unpin from Start'} | %{$_.DoIt(); $exec = $true}

                   if ($exec) {

                       Write "App '$appname' unpinned from Start"

                   } else {

                       if (-not $path -eq "") {

                           Pin-App-by-Path $path -Action $action -start

                       } else {

                           Write "'$appname' not found or 'Unpin from Start' not found on item!"

                       }

                   }

               } else {

                   ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace('&','') -match 'Pin to Start'} | %{$_.DoIt(); $exec = $true}

                   if ($exec) {

                       Write "App '$appname' pinned to Start"

                   } else {

                       if (-not $path -eq "") {

                           Pin-App-by-Path $path -Action $action -start

                       } else {

                           Write "'$appname' not found or 'Pin to Start' not found on item!"

                       }

                   }

               }

           } catch {

               Write-Error "Error Pinning/Unpinning $appname to/from Start!"

           }

       }

    }

    function Pin-App-by-Path([string]$Path, [string]$Action, [switch]$start) {

       if ($Path -eq "") {

           Write-Error -Message "You need to specify a Path" -ErrorAction Stop

       }

       if ($Action -eq "") {

           Write-Error -Message "You need to specify an action: Pin or Unpin" -ErrorAction Stop

       }

       if ((Get-Item -Path $Path -ErrorAction SilentlyContinue) -eq $null){

           Write-Error -Message "$Path not found" -ErrorAction Stop

       }

       $Shell = New-Object -ComObject "Shell.Application"

       $ItemParent = Split-Path -Path $Path -Parent

       $ItemLeaf = Split-Path -Path $Path -Leaf

       $Folder = $Shell.NameSpace($ItemParent)

       $ItemObject = $Folder.ParseName($ItemLeaf)

       $Verbs = $ItemObject.Verbs()

       if ($start.IsPresent) {

           switch($Action){

               "Pin"   {$Verb = $Verbs | Where-Object -Property Name -EQ "&Pin to Start"}

               "Unpin" {$Verb = $Verbs | Where-Object -Property Name -EQ "Un&pin from Start"}

               default {Write-Error -Message "Invalid action, should be Pin or Unpin" -ErrorAction Stop}

           }

       } else {

           switch($Action){

               "Pin"   {$Verb = $Verbs | Where-Object -Property Name -EQ "Pin to Tas&kbar"}

               "Unpin" {$Verb = $Verbs | Where-Object -Property Name -EQ "Unpin from Tas&kbar"}

               default {Write-Error -Message "Invalid action, should be Pin or Unpin" -ErrorAction Stop}

           }

       }

       if($Verb -eq $null){

           Write-Error -Message "That action is not currently available on this Path" -ErrorAction Stop

       } else {

           $Result = $Verb.DoIt()

       }

    }

    Pin-App "Microsoft Edge" -unpin -taskbar

    Pin-App "Store" -unpin -taskbar

    Pin-App "Fresh Paint" -unpin -start

    Pin-App "Wunderlist" -unpin -start

    Pin-App "Network Speed Test" -unpin -start

    Pin-App "Microsoft Edge" -unpin -start

    Pin-App "Alarms & Clock" -unpin -start

    Pin-App "Remote Desktop" -unpin -start

    Pin-App "Voice Recorder" -unpin -start

    Pin-App "Bing Wikipedia Browser" -unpin -start

    Pin-App "Photos" -unpin -start

    Pin-App "Calculator" -unpin -start

    Pin-App "Maps" -unpin -start

    Pin-App "Microsoft Store" -unpin -taskbar

    Set-OSCPin -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Outlook 2016.lnk"

    Set-OSCPin -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Word 2016.lnk"

    Set-OSCPin -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Excel 2016.lnk"

    Set-OSCPin -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Skype for Business 2016.lnk"

    Set-OSCPin -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Mozilla Firefox.lnk"

    Set-OSCPin -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Google Chrome.lnk"

    Set-OSCPin -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Remote Desktop Connection.lnk"

    Set-OSCPin -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\OpenVPN Connect.lnk"

    Set-OSCPin -path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\OneNote 2016.lnk"

    Set-OSCPin -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PowerPoint 2016.lnk"

    Pin-App "Mail" -unpin -start

    Pin-App "Store" -unpin -taskbar

    Pin-App "Calendar" -unpin -start

    Pin-App "Microsoft Edge" -unpin -start

    Pin-App "Microsoft Edge" -unpin -taskbar

    Pin-App "Photos" -unpin -start

    Pin-App "Cortana" -unpin -start

    Pin-App "Cortana" -unpin -taskbar

    Pin-App "Weather" -unpin -start

    Pin-App "Phone Companion" -unpin -start

    Pin-App "Music" -unpin -start

    Pin-App "xbox" -unpin -start

    Pin-App "movies & tv" -unpin -start

    Pin-App "microsoft solitaire collection" -unpin -start

    Pin-App "money" -unpin -start

    Pin-App "get office" -unpin -start

    Pin-App "onenote" -unpin -start

    Pin-App "news" -unpin -start

    Pin-App "Groove Music" -unpin -start

    Pin-App "Sway" -unpin -start

    Pin-App "Skype" -unpin -start

  • You typed start instead of taskbar. I have sent you for start before.

  • The VBS script above returned this error for me:

    The only thing i changed in the VBS was the last lines where i put in my own path the the shortcut i want to add to start menu. 

  • Why don't you use powershell?

  • Didnt realize that was a powershell script. Just assumed it was vbs

  • Any thoughts on this error:

    I took your PS and just changed the last line to:

    Set-OSCPin -Path "C:\TabushSMA\Disconnect from Boxtop.lnk"

  • Did you try to open that shortcut via this url? ("C:\TabushSMA\Disconnect from Boxtop.lnk") .

    Check if you didn't changed anything else. (copy it again from my post) and try. It should work without problem.