1

I'd like to get the target information from a shortcut file using my silverlight OOB app, so I'm going to make the following code to work in my silverlight OOB. It seems I have to used P/Invoke to use Shell32.dll, but I'm not sure how I can use Folder, FolderItem, and ShellLinkObject? Most references explain how I can use the functions in the .dll using P/invoke:( Please give me any 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 Answer 1

0

I 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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.