VB6获取快捷方式lnk文件的指向绝对路径

来源:互联网 发布:如何关闭135和445端口 编辑:程序博客网 时间:2024/06/05 02:01

就是直接艹lnk的文件结构罢了。

Private Declare Sub GetMem2 Lib "msvbvm60" (ByVal Ptr As Long, RetVal As Integer)Private Declare Sub GetMem4 Lib "msvbvm60" (ByVal Ptr As Long, RetVal As Long)Private Declare Sub MoveMemory Lib "msvbvm60" Alias "__vbaCopyBytesZero" (ByVal Length As Long, ByVal Dst As Long, ByVal Src As Long)Private Declare Function lstrlenA& Lib "kernel32" (ByVal lpString&)Private Function QueryShortcutFilePath$(ByVal lnkFile$)Dim pFlag&, pFileInfo&, pFilePath&, pSHHeadLength%, strFilePath$, lpBuffer() As ByteOpen lnkFile For Binary Access Read As #1ReDim lpBuffer(LOF(1) - 1)Get #1, , lpBufferClose #1GetMem4 VarPtr(lpBuffer(0)), pFlagIf pFlag = &H4C ThenGetMem2 VarPtr(lpBuffer(76)), pSHHeadLengthpFileInfo = &H4C + pSHHeadLength + 2If lpBuffer(pFileInfo + 8) = 1 Then '//local fileIf lpBuffer(pFileInfo + 40) = 16 Then  '//test okpFilePath = pFileInfo + 44pFilePath = pFilePath + lstrlenA(VarPtr(lpBuffer(pFilePath))) + 1 '// jump volume labelIf lstrlenA(VarPtr(lpBuffer(pFilePath))) > 0 ThenstrFilePath = Space$(260)MoveMemory lstrlenA(VarPtr(lpBuffer(pFilePath))) + 1, StrPtr(strFilePath), VarPtr(lpBuffer(pFilePath))strFilePath = LeftB$(strFilePath, lstrlenA(StrPtr(strFilePath)))QueryShortcutFilePath = StrConv(strFilePath, vbUnicode)End IfEnd IfEnd IfEnd IfEnd FunctionPrivate Sub Form_Load()Dim strCmd$strCmd = Replace$(Command$, Chr$(34), vbNullString)Me.Caption = QueryShortcutFilePath(strCmd)End Sub