Author Topic: OT (sorry) extract full path by .lnk file  (Read 2409 times)

0 Members and 1 Guest are viewing this topic.

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
OT (sorry) extract full path by .lnk file
« on: November 26, 2021, 07:11:07 am »
I ask you why here is a well of knowledge... :) really... the record joking but it's the truth

and because I've been looking for the solution for days and I can't find it elsewhere...

Do you have, please, idea how to write a batch file (DOS) to extract the complete path of a .LNK (link) file?


(common knowing can also be useful for apps created with QB64...)
Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: OT (sorry) extract full path by .lnk file
« Reply #1 on: November 26, 2021, 07:39:33 am »
I'm not certain how one would go about doing such a thing in a DOS-style batch file, but I'm thinking the below should work for a QB64 program:

Code: QB64: [Select]
  1. Open "Xmas.7z - Shortcut.lnk" For Binary As #1
  2. l = LOF(1)
  3. s$ = Space$(l)
  4. Get #1, 1, s$
  5.  
  6. start = InStr(s$, "DATA") + 5
  7. finish = InStr(start, s$, Chr$(0))
  8. Print Mid$(s$, start, finish - start)


You'll have to use your own LNK file for testing, as trying to upload one simply redirects to the linked file and tries to upload it rather than the *.LNK file itself.  :P

If my thinking is right, all LNK files have a "DATA" + CHR$(0) field, followed by the path to what they're linking to, followed by another CHR$(0).  With use of INSTR, you should be able to get the information you need just by parsing and extracting that amount of information from the file, like above.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: OT (sorry) extract full path by .lnk file
« Reply #2 on: November 27, 2021, 03:14:31 am »
Thank you SMcNeill,
the dear old QB64 is versatile is with a little imagination you can do a lot of things.

Unfortunately the encoding of the links follows an almost incomprehensible rule.
Going back is difficult, almost impossible, if you do not know the code with which the link was encrypted.

Incidentally, years ago, with the system suggested by you, with QB I had written a small program that converted a huge DBF database into another format (without losing a comma!).
It was possible because it is possible to identify the DBF encoding rule with ease.


Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)