Trying to read a shortcut

Archives Forums/Win32 Discussion/Trying to read a shortcut

John Blackledge(Posted 2014) [#1]
I'm trying to get the contents of a dropped shortcut (-got the dropped bit working).
Unfortunately this causes a MAV, and I don't understand the code well enough.
Can anybody help?

Graphics 800,600
pszLinkto$ = "C:\Documents and Settings\John\Desktop\Lifestory.doc.lnk" ; test shortcut
pszDir$ = Chr$(0) ;= String$(" ",512) ; neither of these make any difference
pszName$ = String$(" ",512)
; \/ This causes a MAV
api_SHGetNewLinkInfo% (pszLinkto$, pszDir$, pszName$, pfMustCopy%, uFlags%) ; Shell32 "SHGetNewLinkInfoA"
Print pszLinkto$
Print pszDir$
Print pszName$

BlitzSupport(Posted 2014) [#2]
You'll most likely have to create a bank to hold each string (I would recommend minimum size of Windows constant MAX_PATH, which is 264 from memory), poke in the relevant strings, and pass the bank handles to the Win32 call.

If you need to read any of the strings afterwards, you'll have to peek the bytes from the relevant bank.

The docs will tell you what hex values to pass for uFlags.

Looks like you'll need to pass an int-sized bank for pfMustCopy too, then read from it afterwards if you need to know its result.

John Blackledge(Posted 2014) [#3]
James, as always, thanks for your support.
What you say makes sense, but I have no idea how to do it.
Fancy having a go?

John Blackledge(Posted 2014) [#4]
I've spent 3 days trying to understand DLLs.
I got fed up and handcoded it in an hour:-
Don't you just love Blitz!

BlitzSupport(Posted 2014) [#5]
Just had a go at this, but it turns out that not only does SHGetNewLinkInfo not do what you want, M$ decided to make it ridiculously complex to just retrieve the target path from a shortcut, and it can't be easily done via Blitz -- there's no simple API call for it.

If your manual parsing of the shortcut file works, then... well done!

virtlands(Posted 2014) [#6]
Hi John BlackLedge , I tried your nice code (3 days on), so far I'm getting this error :

It sort of works.

virtlands(Posted 2014) [#7]
You may like the following topics on LNK files :

LNK-parser is open-source; You can compile this with Visual C++ 2008 Express (or later).

ReadLNKFile.CPP -- a Workaround for IShellLink::GetPath() -->

Download the PDF on [MS-SHLLINK]: Shell Link (.LNK) Binary File Format

Optionally, you may get the entire Windows_Protocols.ZIP if you wish --> (=438 files, 408MB)

MSDN website on LNK files ::
LNK File structure Example ::

IShellLink interface is used to read & modify LNK files ::

ResolveIt - { C++ Example } -- Use IShellLink and IPersistFile interfaces
to retrieve path and description from a LNK.

Another ResolveIt Example ::

Creating & Modifying ShortCuts ::
ShellLink Code ::

GetShortcutTarget {C++ Code} ::

IShellLink Example from Dsource.Org ::

Windows Shortcut File (LNK) format PDF -- (shows detailed info on the LNK file Header, etc...)

LibLNK package contains a library & apps to read LNK files.

Windows File & shortcut analyzer

Windows LNK Parsing Utility (lp)

(API) Create ShortCut Function [Danilo Code]

CreateShortCut {C++ Code} ::
How to Create ShortCuts {C++ Code} ::

LNK Parsing, you're doing it wrong... (Parts i & ii)