C# .NET 4.5 Getting target of shortcut without shell32.shell()

Viewed 2084

I'm not a very experienced programmer and new at C#, and I'm having some problems getting the target of a shortcut using shell32.shell(). I found the code here on stackoverflow - and it works beautifully on regular Windows PC's, but when executed on a Citrix virtualized Windows desktop (where I need it to run) it breaks.

The code runs through shortcuts in a folder via a foreach loop, and filters out any that has an executable target. Problem is that to find the target of the shortcut I use the code below, and as soon as it is called the foreach breaks and doesn't progress any further (on Citrix).

I have determined that the break happens at the line "var shl = new Shell32.Shell();", the code after that line doesn't fire and it exits the foreach (but continues executing code after the foreach).

public static string GetLnkTarget(string lnkPath)
{
    var shl = new Shell32.Shell();
    lnkPath = System.IO.Path.GetFullPath(lnkPath);
    var dir = shl.NameSpace(System.IO.Path.GetDirectoryName(lnkPath));
    var itm = dir.Items().Item(System.IO.Path.GetFileName(lnkPath));
    var lnk = (Shell32.ShellLinkObject)itm.GetLink;
    return lnk.Target.Path;
}

Does anyone know of an alternate way to find the target of a shortcut that'll work in a Citrix virtualized environment?

1 Answers
Related