0

From c++ i create a shortcut link for an executable file. It works fine but if the exetuable folder has changed path the link is not workable anymore.(it pops the classic search for the missing file mannually).

If i create a shorcut link from windows by just dragging the executable file to the path i want to create the link and then change folder paths it still finds the executable and updates the paths of the shortcut link without manually search or anything like this.

How can i do that from c++ too ? i tried using arguments but arguments i guess is only for use from command prompt and doesnt update the links just by running the shortcut link.

Here is a link on how i did it in c++ How to programmatically create a shortcut using Win32

Asesh
  • 3,186
  • 2
  • 21
  • 31
Vas
  • 75
  • 9
  • 1
    That SO answer is just a copy/paste from the [MSDN article](https://msdn.microsoft.com/en-us/library/bb776891(VS.85).aspx). Use the ResolveIt sample code instead. – Hans Passant Sep 28 '17 at 15:41
  • "An application may need to access and manipulate a shortcut that was previously created. This operation is referred to as resolving the shortcut."Well by that and only i didnt check if this by itself will update the shorcut since the shortcut cant find the application itself. Will it do the job or will it be just a waste of time ? Thats why i ask here for someone who allready did that and knows for sure what to do ... – Vas Sep 28 '17 at 15:44
  • 1
    The implied assumption in your question is that you somehow know what happened to the link target and can thus update the Path property If you don't know, and how could you know, then it is indeed a waste of time. – Hans Passant Sep 28 '17 at 15:52
  • Windows looks for a moved/renamed target automatically when the shortcut is invoked. The more information the shortcut has about the original target, the better its chances of finding the target if it has been moved/renamed. For instance, are you assigning an ITEMIDLIST (`IShellLink::SetIDList()`) to the shortcut, or just a path string (`IShellLink::SetPath()`)? If no ITEMIDLIST, try adding that. – Remy Lebeau Sep 28 '17 at 16:08
  • @Remy: The standard IShellLink implementation usually fills in the PIDL when you save as a .lnk – Anders Sep 28 '17 at 22:49

1 Answers1

0

The shell simply uses the IShellLink::Resolve method.

Resolve uses information stored in the .lnk to find the moved target. The information includes the created/modified date, the size and the file attributes. The Distributed Link Tracking Service might also be able to help if it is running.

See this Windows Confidential article for details about Windows 95 vs Windows NT and this KB article and this web page for information about LTS.

Anders
  • 97,548
  • 12
  • 110
  • 164
  • I will try it again though i tried and didnt work well. I will try once more maby this time it will work, thanks for you detailed reply Anders – Vas Sep 29 '17 at 10:07