Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Enumerate all shortcuts from .lnk files

  • Filter
  • Time
  • Show
Clear All
new posts

  • George Bleck
    Just to give credit where credit is due, most, if not all the code I used was from Semen Matusovski "create link" code.

    George W. Bleck
    Senior System Engineer
    KeySpan Corporation

    Leave a comment:

  • Wayne Diamond
    started a topic Enumerate all shortcuts from .lnk files

    Enumerate all shortcuts from .lnk files

    full credit for this goes to florent heyworth and george bleck as their getlinkinfo() function is at the heart of this pb/cc program that simply looks for all .lnk files in the path specified in command$ and then stdout's the shortcuts that theyre pointing to
    #compile exe "listlnks.exe"
    #include ""
    declare function coinitialize lib "ole32.dll" alias "coinitialize"( byval pvreserved as dword ) as dword
    declare function cocreateinstance lib "ole32.dll" alias "cocreateinstance"( rclsid as string * 16, byval punkouter as any, byval dwclscontext as dword, riid as string * 16, ppv as dword ) as dword
    declare sub couninitialize lib "ole32.dll" alias "couninitialize"
    declare sub cotaskmemfree lib "ole32.dll" alias "cotaskmemfree"( pv as dword )
    declare function sub1( p1 as any ) as dword
    declare function sub2( p1 as any, p2 as any ) as dword
    declare function sub3( p1 as any, p2 as any, p3 as any ) as dword
    declare function sub5( p1 as any, p2 as any, p3 as any, p4 as any, p5 as any ) as dword
    sub getlinkinfo( linkpath as string )
    'by florent heyworth and george bleck
    'modified to exclude unnecessary shelllink variables,
    'please see original at [url=""][/url] 
        local clsctx_inproc_server as dword
        local clsid_shelllink as string * 16
        local filedata as win32_find_data
        local flags as dword
        local iid_ishelllink as string * 16
        local iid_persist as string * 16
        local lresult as dword
        local outvalue as asciiz * 128
        local pp as dword ptr
        local ppf as dword ptr
        local psl as dword ptr
        local tmpasciiz as asciiz * %max_path
        local tmpwide as asciiz * ( 2 * %max_path )
        clsid_shelllink = mkl$( &h00021401 ) + chr$( 0, 0, 0, 0, &hc0, 0, 0, 0, 0, 0, 0, &h46 )
        iid_ishelllink = mkl$( &h000214ee ) + chr$( 0, 0, 0, 0, &hc0, 0, 0, 0, 0, 0, 0, &h46 )
        iid_persist = mkl$( &h0000010b ) + chr$( 0, 0, 0, 0, &hc0, 0, 0, 0, 0, 0, 0, &h46 )
        clsctx_inproc_server = 1
        if isfalse( cocreateinstance( clsid_shelllink, %null, clsctx_inproc_server, iid_ishelllink, psl )) then
            pp = @psl: call dword @pp using sub3( byval psl, iid_persist, ppf ) to lresult
            tmpasciiz = linkpath
            multibytetowidechar %cp_acp, 0, tmpasciiz, - 1, tmpwide, %max_path
            pp = @ppf + 20: call dword @pp using sub3( byval ppf, tmpwide, byval %true )
            pp = @psl + 12: call dword @pp using sub5( byval psl, outvalue, byval %max_path, filedata, flags )
            if trim$(outvalue) <> " then stdout outvalue
            exit sub
         end if
    end sub
    sub findlnkfiles(path as string)
    on error resume next
      local wfd         as win32_find_data
      local flname      as string        ' walking filename variable...
      local dirname     as string        ' subdirectory name
      redim dirnames(0) as local string  ' array for sub directories
      local ndir        as long          ' number of directories in this path
      local hsearch     as long          ' search handle
      local cnt         as long          ' for a counter in for/next loop
      local fres        as integer       ' for a true or false -flag
      local curpath     as asciiz * %max_path 'for the findfirstfile calls
      if right$(path, 1) <> "\" then path = path & "\"
      curpath = path & "*.*"
      hsearch = findfirstfile(curpath, wfd)
      if hsearch <> %invalid_handle_value then 'get subdirectories
         fres = %true
         do while fres
           dirname = rtrim$(wfd.cfilename, chr$(0))
           if (wfd.dwfileattributes and 16) = 16 then
               if asc(wfd.cfilename) <> 46 then   'not . or ..
                  if ndir mod 50 = 0 then redim preserve dirnames(ndir + 50)
                  dirnames(ndir) = dirname
                  incr ndir
               end if
             flname = rtrim$(wfd.cfilename, chr$(0))
             if lcase$(right$(flname,4)) = ".lnk" then
                '*** display the lnk file:
                    'stdout path & flname
                '*** display the shortcut location
                     getlinkinfo path & flname
             end if
           end if
           fres = findnextfile(hsearch, wfd) 'get next subdirectory
         fres = findclose(hsearch)
        exit sub
     end if
      if ndir then               'if there were any sub-directories..
         for cnt = 0 to ndir - 1
            call findlnkfiles(path & dirnames(cnt) & "\")
         next cnt
      end if
    end sub
    function pbmain() as long
    on error resume next
     local cmd$
     cmd$ = command$
     if trim$(cmd$) = " then
        stdout "usage: listlnks <path>"
        stdout "   eg. listlnks c:\winnt\profiles"
        exit function
     end if
     coinitialize %null
     if right$(cmd$,1) <> "\" then cmd$ = cmd$ & "\"
     call findlnkfiles(cmd$)
    end function

    [this message has been edited by wayne diamond (edited june 25, 2001).]