I found and altered this code, works for me:
static string GetShortcutTargetFile(string shortcutFilename)
{
string pathOnly = System.IO.Path.GetDirectoryName(shortcutFilename);
string filenameOnly = System.IO.Path.GetFileName(shortcutFilename);
Shell32.Shell shell = new Shell32.Shell();
Shell32.Folder folder = shell.NameSpace(pathOnly);
Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
if (folderItem != null)
{
return ((Shell32.ShellLinkObject)folderItem.GetLink).Path;
}
return ""; // not found, use if (File.Exists()) in the calling code
// or remove the return and throw an exception here if you like
}
You have to add a reference to the Microsoft Shell Controls And Automation
COM object (Shell32.dll) to the project to make this work.