.NET读取.lnk文件的二进制内容
我想读取 .lnk 文件的二进制内容。 只要快捷方式的目标(lnk 文件)存在,就可以与 IO.File.ReadAllBytes(string file) 一起正常工作。
但是
如果快捷方式的目标不存在(相信我,我想要这个),该方法仅返回零。我想这是因为操作系统遵循链接,如果它不存在,则返回零。
是否有某种方法可以绕过框架在显示 .lnk 文件内容之前遵循 .lnk 目标的事实?
I want to read the binary contents of a .lnk file.
As long as the target of the shortcut (lnk file) exists this works fine with IO.File.ReadAllBytes(string file).
BUT
If the target of the shortcut does not exist (believe me I want this) the method only returns zero's. I guess this is because the OS follows the link and if it does not exist it returns zero's
Is there some way to bypass the fact that the framework follows the target of the .lnk before displaying the contents of the .lnk file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这没有多大意义,没有简单的方法来检查它。我认为最好的方法是以应有的方式读取 .lnk 文件。您可以使用 COM 来执行此操作,ShellLinkObject 类 实现 IShellLink 接口。开始使用“项目 + 添加引用”、“浏览”选项卡并导航到 c:\windows\system32\shell32.dll。这会生成一个互操作库。像这样编写代码:
It doesn't make a lot of sense, don't have an easy way to check it. I reckon the best approach is to read the .lnk file the way it is supposed to be read. You can use COM to do so, the ShellLinkObject class implements the IShellLink interface. Get started with Project + Add Reference, Browse tab and navigate to c:\windows\system32\shell32.dll. That generates an interop library. Write code like this:
我不相信 ReadAllBytes 会导致操作系统跟随 lnk 到达其目标。我怀疑,操作系统已经解析了 lnk 文件(也许当您在 Windows 资源管理器中浏览到该文件时)。
I don't believe ReadAllBytes induces the OS to follow the lnk to its target. I suspect, the OS has already resolved the lnk file (maybe when you browsed to the file in Windows Explorer).
事实证明该文件被锁定,因为它是从另一台计算机(我使用的是服务器 2008 r2)复制的,解锁它会返回预期的行为。
愚蠢的我。
Turns out the file was locked because it was copied from another machine (i'm using server 2008 r2) unlocking it returned the behavoir to expected.
Stupid me.