首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Silverlight OOB中使用Shell32.dll

如何在Silverlight OOB中使用Shell32.dll
EN

Stack Overflow用户
提问于 2013-01-27 04:15:23
回答 1查看 352关注 0票数 1

我想使用我的silverlight OOB应用程序从快捷方式文件中获取目标信息,因此我将编写以下代码以在我的silverlight OOB中工作。似乎我必须使用P/Invoke来使用Shell32.dll,但我不确定如何使用文件夹、FolderItem和ShellLinkObject?大多数参考资料都解释了如何使用P/invoke使用.dll中的函数:(请给我任何注释或示例代码/链接:)

代码语言:javascript
复制
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
}
EN

回答 1

Stack Overflow用户

发布于 2015-01-27 03:37:34

我找到了一个解决方案。

代码语言:javascript
复制
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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14541151

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档