How I can use Shell32.dll in Silverlight OOB

 ̄綄美尐妖づ 提交于 2020-01-05 05:50:50

问题


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:


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
}


来源:https://stackoverflow.com/questions/14541151/how-i-can-use-shell32-dll-in-silverlight-oob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!