dongmi4734 2017-05-24 21:02
浏览 64

使用Go阅读快捷方式的目标

I'm trying to read the target file/directory of a shortcut (.lnk) file using Go.

I already have a loop for all the files in a directory and I can successfully identify if it is a dir with IsDir() or if it is a file IsRegular(). Now I need a way to read if it is a link and, if it is a .lnk, the path of it so I can print it.

I couldn't find any way of doing this and I've been searching on SO but nothing comes up. Any idea?

  • 写回答

1条回答 默认 最新

  • douhuiqi3855 2017-05-24 21:30
    关注

    You need to read the lnk binary format as defined by Microsoft

    In Go, its structure would translate to (as used in the exponential-decay/shortcuts)

    //structs that make up the shortcut specification [76 bytes] 
    type ShellLinkHeader struct {
       HeaderSize  [4]byte           //HeaderSize
       ClassID     [16]byte          //LinkCLSID
       LinkFlags   uint32            //LinkFlags      [4]byte
       FileAttr    uint32            //FileAttributes [4]byte
       Creation    [8]byte           //CreationTime
       Access      [8]byte           //AccessTime
       Write       [8]byte           //WriteTime
       FileSz      [4]byte           //FileSize
       IconIndex   [4]byte           //IconIndex
       ShowCmd     [4]byte           //ShowCommand
    
       //[2]byte HotKey values for shortcut shortcuts
       HotKeyLow   byte              //HotKeyLow
       HotKeyHigh  byte              //HotKeyHigh
    
       Reserved1   [2]byte           //Reserved1
       Reserved2   [4]byte           //Reserved2
       Reserved3   [4]byte           //Reserved3
    }
    

    That project should give you an idea to how to decode the shortcut target.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog