您的位置:首页 > 编程语言 > VB

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

2012-08-03 00:45 357 查看
就是直接艹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 Byte
Open lnkFile For Binary Access Read As #1
ReDim lpBuffer(LOF(1) - 1)
Get #1, , lpBuffer
Close #1
GetMem4 VarPtr(lpBuffer(0)), pFlag
If pFlag = &H4C Then
GetMem2 VarPtr(lpBuffer(76)), pSHHeadLength
pFileInfo = &H4C + pSHHeadLength + 2
If lpBuffer(pFileInfo + 8) = 1 Then '//local file
If lpBuffer(pFileInfo + 40) = 16 Then  '//test ok
pFilePath = pFileInfo + 44
pFilePath = pFilePath + lstrlenA(VarPtr(lpBuffer(pFilePath))) + 1 '// jump volume label
If lstrlenA(VarPtr(lpBuffer(pFilePath))) > 0 Then
strFilePath = Space$(260)
MoveMemory lstrlenA(VarPtr(lpBuffer(pFilePath))) + 1, StrPtr(strFilePath), VarPtr(lpBuffer(pFilePath))
strFilePath = LeftB$(strFilePath, lstrlenA(StrPtr(strFilePath)))
QueryShortcutFilePath = StrConv(strFilePath, vbUnicode)
End If
End If
End If
End If
End Function

Private Sub Form_Load()
Dim strCmd$
strCmd = Replace$(Command$, Chr$(34), vbNullString)
Me.Caption = QueryShortcutFilePath(strCmd)
End Sub
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: