我想使用我的silverlight OOB应用程序从快捷方式文件中获取目标信息,因此我将编写以下代码以在我的silverlight OOB中工作。似乎我必须使用P/Invoke来使用Shell32.dll,但我不确定如何使用文件夹、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
}发布于 2015-01-27 03:37:34
我找到了一个解决方案。
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
复制相似问题