Shortcuts (.lnk)

Just starting out? Need help? Post your questions and find answers here.
Phant0m``

Shortcuts (.lnk)

Post by Phant0m`` »

I looked all over the place and I couldn’t find anything that retrieves Target Info from Shortcuts (.lnk)….

Are there any posts that I could be referred to?

Thanks in Advanced...
Phant0m``

Post by Phant0m`` »

N/M, i figured it out :)
Phant0m``

Post by Phant0m`` »

OK this is stupid, i spoke to soon...

I thought i had it because using

Code: Select all

Debug OpenFileRequester("Choose file","","",0)
It returns with Target rather then the .lnk but when i use OpenFile() it returns with .lnk.... I'm stumped :x
Kris_a
User
User
Posts: 92
Joined: Sun Feb 15, 2004 8:04 pm
Location: Manchester, UK

Post by Kris_a »

I found this document that explains how the LNK file format works, perhaps you could have a read then make some sort of interpreter in PB?

http://www.the7soft.com/file-formats/fi ... /lnk_c.zip
Phant0m``

Post by Phant0m`` »

To some sort of interpreter in PB is well out of my lead at this time, I only began programming in general the other week.

I know one thing, shouldn’t be this hard just to retrieve Shortcut Target Informatics. :/
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Try this:

Target$ = ShortcutTarget(Shortcut$)

Code: Select all

Procedure.s ShortcutTarget(ShortcutFile$)
  Result$ = ""
  
  CoInitialize_(0)
  If CoCreateInstance_(?CLSID_ShellLink, 0, 1,?IID_IShellLink, @ShellLink.IShellLinkA) = #S_OK
    
    If ShellLink\QueryInterface(?IID_IPersistFile, @LinkFile.IPersistFile) = #S_OK
    
      *buffer = AllocateMemory(1000)
      If *buffer
      
        MultiByteToWideChar_(#CP_ACP, 0, @ShortcutFile$, -1, *buffer, 1000) 
        
        If LinkFile\Load(*buffer, 0) = #S_OK
        
          If ShellLink\Resolve(0, 1) = #S_OK
          
            RtlZeroMemory_(*buffer, 1000)
            ShellLink\GetPath(*buffer, 1000, 0, 0)
            Result$ = PeekS(*buffer)              
          
          EndIf
        
        EndIf
      
        FreeMemory(*buffer)
      EndIf
    
      LinkFile\Release()
    EndIf

    ShellLink\Release()  
  EndIf
  
  CoUninitialize_()
  
  ProcedureReturn Result$

  DataSection
    CLSID_ShellLink:
      ; 00021401-0000-0000-C000-000000000046
      Data.l $00021401
      Data.w $0000,$0000      
      Data.b $C0,$00,$00,$00,$00,$00,$00,$46
      
    IID_IShellLink:
      ; DEFINE_SHLGUID(IID_IShellLinkA,         0x000214EEL, 0, 0);
      ; C000-000000000046
      Data.l $000214EE
      Data.w $0000,$0000
      Data.b $C0,$00,$00,$00,$00,$00,$00,$46
      
    IID_IPersistFile:
      ; 0000010b-0000-0000-C000-000000000046
      Data.l $0000010b
      Data.w $0000,$0000
      Data.b $C0,$00,$00,$00,$00,$00,$00,$46
  EndDataSection
EndProcedure
Timo
quidquid Latine dictum sit altum videtur
Phant0m``

Post by Phant0m`` »

Now you just simply a programming G0d, thanks freak....
Phant0m``

Post by Phant0m`` »

How about Windows Tasks files (.job) ?
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Never heard of that, sorry :?
quidquid Latine dictum sit altum videtur
Phant0m``

Post by Phant0m`` »

.job files are files stored in Windows Tasks folder (\WINDOWS\Tasks), it is pretty much a shortcut. If you actually copy the file over to another place, and open up with notepad you can actually see Target Information in ASCII.
Post Reply