3

I am searching for a way to remove broken shortcuts from my windows machine through c/c++ code. I found some software which does the same(Microsoft Fix It) but no information in the net on how this is done via coding.

let me know if any sample code or api are available to achieve the same.

Note:It is bit confusing to others about what kind of shortcut i was referring to, Here basically i am looking for desktop and explorer shortcuts as a first step.

Darshan
  • 121
  • 1
  • 11
  • What kind of "shortcut"? There are filesystem-level links or the more common Explorer links which are just files with the extension ".LNK" and which are interpreted by Explorer. – Ulrich Eckhardt Dec 22 '15 at 08:58
  • Windows also has what it calls a `Internet Shortcut` which is typically something like `myfile.url` These are text files. – Marichyasana Dec 22 '15 at 12:33

1 Answers1

4

You did not specify what kind of shortcuts, so I'll assume you want to do this with desktop and/or start-menu shortcuts.

This would require a few steps:

  1. First, you'll need to locate the shortcuts, which are ".lnk" files. You can use the SHGetFolderPath command to find the location of a few relevant folders such as the Start Menu. See this SO answer for a bit more details.
  2. Dealing with shortcut files in Windows is not trivial. See the shell-links reference in MSDN. Look for the "Resolving a shortcut" example. Take a look at the "ResolveIt" function to see how to query various properties of a shortcut file.
  3. Now look for the shortcut destination and figure out if it's broken (e.g. destination path does not exist).
Community
  • 1
  • 1
Itaypk
  • 1,103
  • 10
  • 25
  • hi itaypk thanks for your immediate reply , i did specify about microsoft fix it tool so even i don't know what and all kind of shortcuts it is considering. I will try the above method and let u know. – Darshan Dec 22 '15 at 07:37