我想使用我的silverlight OOB应用程序从快捷方式文件中获取目标信息,因此我将在Silverlight OOB中使用以下代码。看来我必须使用P / Invoke来使用Shell32.dll,但我不确定如何使用Folder,FolderItem和ShellLinkObject?大多数参考资料解释了如何使用P / invoke在.dll中使用函数:(请给我任何评论或示例代码/链接:)
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
}
答案 0 :(得分:0)
我找到了解决方案。
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
}