How can I use Shell32.dll in Silverlight OOB

I would like to get the target information from a shortcut file using my OOB application for Silverlight, so I'm going to make the following code to work in my Silverlight OOB. It seems I need to use P / Invoke to use Shell32.dll, but I'm not sure how I can use Folder, FolderItem and ShellLinkObject? Most links explain how I can use functions in .dll using P / invoke :( Please give me comments or sample code / links :)

public string GetShortcutTargetFile(string shortcutFilename)
{
  string pathOnly = Path.GetDirectoryName(shortcutFilename);
  string filenameOnly = Path.GetFileName(shortcutFilename);

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

  return String.Empty; // Not found
}
+1
source share
1 answer

I have found a solution.

public string GetShortcutTargetFile(string shortcutFilename)
{
    string pathOnly = System.IO.Path.GetDirectoryName(shortcutFile);
    string filenameOnly = System.IO.Path.GetFileName(shortcutFile);

    dynamic shell = AutomationFactory.CreateObject("Shell.Application");
    dynamic folder = shell.NameSpace(pathOnly);
    dynamic folderItem = folder.ParseName(filenameOnly);
    if (folderItem != null)
    {
        dynamic link = folderItem.GetLink;
        return "\""+link.Path +"\"" + " " + link.Arguments;
    }

    return String.Empty; // Not found
}
0
source

Source: https://habr.com/ru/post/1748169/


All Articles