How to get the real target of a shortcut?
I have a shortcut on the desktop, that opens Adobe Reader XI, in the following path:
C:\Users\Heiko\Desktop\Adobe Reader XI.lnk
In my app, I am trying to get the destinations of various shortcuts. However, with Adobe Reader XI, I only get an ico file as a target. When I look at the properties of the shortcut on the desktop, the target field is locked and the name of the app is shown in it.
However, if I start the lnk file with Process.Start()
, a process is started with C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe.
// Add Reference to 'Microsoft Shell Controls And Automation' from COM area.
Shell32.Shell shell = new Shell32.Shell();
Shell32.Folder folder = shell.NameSpace(@"C:\Users\Heiko\Desktop");
foreach (Shell32.FolderItem item in folder.Items())
{
if (item.IsLink)
{
Shell32.ShellLinkObject lnk = item.GetLink;
Shell32.FolderItem target = lnk.Target;
string path = target.Path; // path: C:\Windows\Installer\{AC76BA86-7AD7-1031-7B44-AB0000000001}\SC_Reader.ico
}
}
target.Path
contains the ico file, although AcroRd32.exe is started. Is there any way to find out if there is a target other than lnk.Target.Path
behind the shortcut?
1 additional answer
Sort by: Most helpful
-
RLWA32 47,616 Reputation points
2023-06-03T14:27:08.4333333+00:00 From the description it sounds like the shortcut on the desktop is what is known as an "advertised" shortcut created by the Windows Installer. Raymond Chen's blog at Why do some shortcuts not support editing the command line and other properties? explains that "Shortcuts to advertise applications and shortcuts to items in the Games folder are not shortcuts to executables. They are shortcuts into the shell namespace for various types of virtual data. An advertised application is a shell namespace object that represents “an installed application”. It is not a pointer directly to the executable, but rather a reference to an entry in the MSI database, which in turn contains information about how to install the program, repair it, update it, and run it. The shell doesn’t even know what the command line is. To launch an advertised shortcut, the shell asks the MSI database for the command line, and it then executes that command line that MSI returns."