A customer explained that they had a program that
used
the IShellLink::
method
to extract the program that is the target of a shortcut.
They found that this
didn't work for certain shortcuts,
namely, shortcuts whose targets are not physical file paths.
The one that they were specifically having trouble with was the Control Panel shortcut. For example, if you open the classic Control Panel, then drag any of the Control Panel items to the desktop, this will create a shortcut to that Control Panel item. If you view the properties on that shortcut, the Target will be grayed out instead of showing a path.
"We want to get the target path of the shortcut
so that we can launch the application.
How can we get the target path from
IShellLink::
?
Is there a special Windows API to get the path?"
They can't get the target path because these are shortcuts to virtual objects. There is no target path to begin with.
But if you look past the question to their problem,
you can see that they don't need to know the path in the first place.
All they want to do is launch the target application.
The way to do this is simply to pass the shortcut to the
ShellExecute
function.
You can take
this simple program as inspiration.
Pass "open"
as the verb
and the full path to the shortcut as the file.
As a bonus: Your program will also respect the other settings in the shortcut, like the Start In folder, the shortcut key, the preferred window state (normal, maximized, etc.), the custom application user model ID.
And to answer the question
(even though it isn't needed to solve the problem):
Use
the
IShellLink::
method
to obtain the shortcut target regardless of whether it is a physical
file or virtual namespace item.