C# - Get the executable path from a Office Windows 10 .lnk file

224 views Asked by At

I'm trying to get the exe path from the Windows 10 Office .lnk file.

e.g.

Link Path - C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Word 2016.lnk

Exe Path - C:\Program Files\Microsoft Office\Office16\WINWORD.EXE

Things I've tried:

Shell shell = new Shell();
Folder folder = shell.NameSpace(pathOnly);
FolderItem folderItem = folder.ParseName(filenameOnly);
if (folderItem != null && folderItem.IsLink)
{
      Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
      return link.Path;
}

AND

IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); //Create a new WshShell Interface
IWshRuntimeLibrary.IWshShortcut link = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(file);
string path = link.TargetPath;

Seems like the paths are stored in the registry at Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Winword.exe But some of the keys are very different to the lnk filename, so not sure how I would link the two.

Anyone got any ideas?

N.B. Most info I can find seems to be out of date

0

There are 0 answers