none
Script to remove broken shortcuts from Windows 7 Start Menu / Task Bar RRS feed

  • Question

  • I am trying to write a vbs script to remove broken shortcuts from the Windows 7 Start Menu and Task Bar.  For example, if you have Office 2013 uninstall Office 2010 as part if it's installation and you had pinned the Word 2010 shortcut to your Start Menu, that Word 2010 shortcut is now broken. I am looking for a way to "clean up" these broken shortcuts in an automated way (i.e. script). I have scripts that can pin and unpin from both the Start Menu and the Taskbar, but they don't work on the broken shortcuts. Any help would be greatly appreciated.

    Thursday, January 8, 2015 8:09 PM

Answers

All replies

  • Or if someone knows of a command line utility that will clean them up. That would work as well.

    Thursday, January 8, 2015 8:15 PM
  • So question #1 is, how can you know a shortcut is broken?

    Probably the simplest way is to use the CreateShortcut method of the WshShell object to open the shortcut file (yes, the CreateShortcut method is used for opening shortcut files also, not just for creating them). This returns a WshShortcut object.

    The WshShortcut object has a TargetPath property that references the target path/filename of the shortcut. You can then check whether the file exists. If the file in TargetPath doesn't exist, then the shortcut would not work.


    -- Bill Stewart [Bill_Stewart]

    Thursday, January 8, 2015 8:19 PM
    Moderator
  • That is a good point, but in the situation (like the example I gave) I am looking really to remove specific shortcuts that I know are indeed broken. After Office 2013 removes Office 2010 any shortcuts (i.e. Word 2010) you had pinned to the Start Menu (or Task Bar) would be a broken icon-less shortcut. Since I am deploying Office 2013 to many computers I am trying to automate a "clean up" process for all existing profiles (it could be something that runs the next time the profile is logged into and then it deletes itself). Of course, any good script would test to see if the shortcut is indeed broken. These will all be Windows 7 machines.

    Thursday, January 8, 2015 8:29 PM
  • If you know what the paths of the broken shortcut files are, just delete them.

    Did you have any other questions?


    -- Bill Stewart [Bill_Stewart]

    Thursday, January 8, 2015 8:32 PM
    Moderator
  • Hi,

    Do you have a specific question?

    If you're looking for prewritten scripts, you can check the script repository here:

    http://gallery.technet.microsoft.com/scriptcenter

    If you don't find what you're looking for and you can't write your own (note that we don't write scripts on demand here in the forum), you can request a script here:

    https://gallery.technet.microsoft.com/scriptcenter/site/requests


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    Thursday, January 8, 2015 8:32 PM
  • That's my problem... the target they referred to no longer exists. I just thought that there was a way to programmatically remove them. I can't find any reference to them in the registry and the program and it "real" shortcut no longer exists. The shortcuts do not even have an icon associated with them anymore.

    Thursday, January 8, 2015 8:40 PM
  • Sorry, I guess I didn't express myself very well. I was just looking for some insight on how to go about it. I will look at the links you provided. Thanks!

    Thursday, January 8, 2015 8:41 PM
  • (?) The suggestion I posted above tells you how you could use a script to open a shortcut file and check whether the target path exists.

    -- Bill Stewart [Bill_Stewart]

    Thursday, January 8, 2015 8:41 PM
    Moderator
  • Sorry, I guess I didn't express myself very well. I was just looking for some insight on how to go about it. I will look at the links you provided. Thanks!

    Okay, gotcha. Bill's already pointed out the best way to get started with this.


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    Thursday, January 8, 2015 8:47 PM
  • Hi George,

    I realize this thread is a few months old, but were you able to come up with a solution? My organization is piloting the deployment of Office 2013 and we've come across the same issue. Outlook 2010, Excel 2010, and Word 2010 are pinned to every user's start menu. When we remove Office 2010 and install Office 2013, the Office 2010 shortcuts remain pinned to the start menu.

    I've written a PowerShell script that removes the pinned items from all profiles in "%appdata%\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu", but the dead shortcuts remain as (what I assume is) some kind of MRU list. I'm currently poking around the registry to see if I can locate where these dead links are stored to get them removed.

    This is where I'm currently looking:

    • HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StartPage2
    • HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist

    Any insight as to how you resolved this issue would be much appreciated.

    Tuesday, March 31, 2015 3:52 PM
  • This question already has an answer. You can find shortcut files (*.lnk) and open them using the WshShell object's CreateShortcut method (yes, that's the correct method name for opening a shortcut; it is badly named). You can look in the TargetPath property; if it does not exist, you can delete the shortcut file.

    -- Bill Stewart [Bill_Stewart]

    Tuesday, March 31, 2015 4:13 PM
    Moderator
  • Hi Bill. Thanks for the quick response. Perhaps I'm not understanding. My apologies if that's the case.

    There is no issue locating the Office 2010 shortcut files and deleting them. The issue is that after we delete the shortcut files there is a broken link in the start menu. I'll try my best to illustrate the process we go through.

    1. Office 2010 is installed and every user has three Office 2010 shortcuts pinned to the start menu.
    2. Office 2010 is uninstalled and Office 2013 is installed.
    3. The items in the Start Menu are still present, but the shortcut (.lnk) files they reference are no longer there.

    4. When you click on the item on the start menu you get the following error message because the shortcut no longer exists:

    In summary, there is no issue deleting the shortcut file. The issue is deleting the “dead links” to the shortcut files that are on the Start Menu, in a scripted manner, because I do not know where Windows stores them.

    Wednesday, April 1, 2015 5:03 PM
  • AFAIK, such APIs are not available to script.

    A pinned item isn't going to know that the application isn't there any more.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 1, 2015 5:26 PM
    Moderator
  • I had this issue for a bit, i came up with the below script to test the path of the exes references in the shortcuts. Please test before running.

    $shell = New-Object -ComObject Wscript.Shell Get-ChildItem -path "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\" -filter *.lnk -Recurse | foreach { $lnk = $shell.createShortcut($_.fullname) $Path = $lnk.targetPath if ([string]::IsNullOrEmpty($Path)) { } else { $testpath = Test-Path "$Path" If ($testpath -eq $False) { Write-host "Broken Shortcut Removing $_" $_ | remove-item } } }


    Thursday, May 26, 2016 4:04 PM
  • I am trying to write a vbs script to remove broken shortcuts from the Windows 7 Start Menu and Task Bar.  For example, if you have Office 2013 uninstall Office 2010 as part if it's installation and you had pinned the Word 2010 shortcut to your Start Menu, that Word 2010 shortcut is now broken. I am looking for a way to "clean up" these broken shortcuts in an automated way (i.e. script). I have scripts that can pin and unpin from both the Start Menu and the Taskbar, but they don't work on the broken shortcuts. Any help would be greatly appreciated.

    I think everyone is misunderstanding his question.  The problem/question is the same issue I am running into. George is referencing user pinned shortcuts not true shortcuts.  The problem is that even if you delete the physical pinned shortcut from the user's "%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu", there is still a reference to it in a binary key under "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartPage2".  There is no straight-forward way to programatically remove stale references from this binary value and therefore a broken pin remains confusing the user.  How does one clean up stale references in the binary keys?
    Tuesday, June 28, 2016 7:55 PM
  • There is no documented method for doing this.  It is a user only step.  The user should be prompted if the shortcut is broken to have the link removed.  If you try to script around this you will likely break the ability for Windows to detect the issue.

    StartPag2 holds favorites and not master links.  It is encoded as a Unicode set of strings.  You would have to write a custom handler to edit it.

    Windows 7 does not use this method.


    \_(ツ)_/



    • Edited by jrv Tuesday, June 28, 2016 8:41 PM
    Tuesday, June 28, 2016 8:35 PM