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

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.

January 8th, 2015 8:09pm

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

Free Windows Admin Tool Kit Click here and download it now
January 8th, 2015 8:15pm

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.

January 8th, 2015 8:19pm

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.

Free Windows Admin Tool Kit Click here and download it now
January 8th, 2015 8:29pm

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

January 8th, 2015 8:32pm

If you know what the paths of the broken shortcut files are, just delete them.

Did you have any other questions?

Free Windows Admin Tool Kit Click here and download it now
January 8th, 2015 8:32pm

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.

January 8th, 2015 8:40pm

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!

Free Windows Admin Tool Kit Click here and download it now
January 8th, 2015 8:41pm

(?) 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.
January 8th, 2015 8:41pm

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.

Free Windows Admin Tool Kit Click here and download it now
January 8th, 2015 8:47pm

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.

March 31st, 2015 11:54am

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.
Free Windows Admin Tool Kit Click here and download it now
March 31st, 2015 12:15pm

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.

April 1st, 2015 1:05pm

AFAIK, such APIs are not available to script.

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

Free Windows Admin Tool Kit Click here and download it now
April 1st, 2015 1:28pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics