Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove broken shortcuts in windows programatically [closed]

Tags:

c++

c

windows

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.

like image 493
Darshan Avatar asked Jan 24 '26 09:01

Darshan


1 Answers

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).
like image 135
Itaypk Avatar answered Jan 25 '26 21:01

Itaypk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!