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$
WaitKey()
End


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:-
http://www.blitzbasic.co.nz/codearcs/codearcs.php?code=3104
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).
:: http://uploadingit.com/file/9nufwv5v674kqoom/lnk-parser.zip
:: https://code.google.com/p/lnk-parser/source/checkout

ReadLNKFile.CPP -- a Workaround for IShellLink::GetPath() -->
:: http://www.codeproject.com/Articles/24001/Workaround-for-IShellLink-GetPath

Download the PDF on [MS-SHLLINK]: Shell Link (.LNK) Binary File Format
:: http://download.microsoft.com/download/9/5/E/95EF66AF-9026-4BB0-A41D-A4F81802D92C/%5BMS-SHLLINK%5D.pdf

Optionally, you may get the entire Windows_Protocols.ZIP if you wish --> (=438 files, 408MB)
:: http://download.microsoft.com/download/9/5/E/95EF66AF-9026-4BB0-A41D-A4F81802D92C/Windows_Protocols.zip

MSDN website on LNK files :: http://msdn.microsoft.com/en-us/library/dd871305.aspx
LNK File structure Example :: http://msdn.microsoft.com/en-us/library/dd871375.aspx

IShellLink interface is used to read & modify LNK files ::
:: http://msdn.microsoft.com/en-us/library/bb774950%28VS.85%29.aspx

ResolveIt - { C++ Example } -- Use IShellLink and IPersistFile interfaces
to retrieve path and description from a LNK.
:: http://msdn.microsoft.com/en-us/library/windows/desktop/bb776891%28v=vs.85%29.aspx

Another ResolveIt Example :: http://www.cplusplus.com/forum/windows/64088/

Creating & Modifying ShortCuts :: http://www.vbaccelerator.com/home/NET/Code/Libraries/Shell_Projects/Creating_and_Modifying_Shortcuts/article.asp
ShellLink Code :: http://www.vbaccelerator.com/home/NET/Code/Libraries/Shell_Projects/Creating_and_Modifying_Shortcuts/ShellLink_Code.asp

GetShortcutTarget {C++ Code} :: http://cboard.cprogramming.com/cplusplus-programming/102794-ishelllink-getpath-method.html

IShellLink Example from Dsource.Org ::
:: http://www.dsource.org/projects/tutorials/wiki/CreateLinkUsingCom

Windows Shortcut File (LNK) format PDF -- (shows detailed info on the LNK file Header, etc...)
:: https://googledrive.com/host/0B3fBvzttpiiSQmluVC1YeDVvZWM/Windows%20Shortcut%20File%20(LNK)%20format.pdf

LibLNK package contains a library & apps to read LNK files.
:: https://github.com/libyal/liblnk/

Windows File & shortcut analyzer
:: http://mitec.cz/Downloads/WFA.zip
:: http://mitec.cz/wfa.html

Windows LNK Parsing Utility (lp)
:: https://www.tzworks.net/prototype_page.php?proto_id=11
:: https://www.tzworks.net/download_links.php



(API) Create ShortCut Function [Danilo Code]
:: http://www.blitzbasic.com/Community/posts.php?topic=99931

CreateShortCut {C++ Code} :: http://www.intelliproject.net/articles/showArticle/index/create_shortcut_cpp_com
How to Create ShortCuts {C++ Code} :: http://www.codeproject.com/Articles/11467/How-to-create-short-cuts-link-files

LNK Parsing, you're doing it wrong... (Parts i & ii)
:: http://blog.0x01000000.org/2010/08/10/lnk-parsing-youre-doing-it-wrong-i/
:: http://blog.0x01000000.org/2010/08/13/lnk-parsing-youre-doing-it-wrong-ii/