Connecting Tech Pros Worldwide Forums | Help | Site Map

lnk batch

Newbie
 
Join Date: Sep 2008
Posts: 1
#1: Sep 16 '08
I would like to have a batch file that outputs the target and shortcut name of all shortcuts in a folder to a text file. Any help at all would be appreciated.

Site Addict
 
Join Date: Feb 2007
Posts: 553
#2: Sep 16 '08

re: lnk batch


Hi

Try this:

Expand|Select|Wrap|Line Numbers
  1. dir *.lnk > c:\abc.txt
  2.  
Change the folder path (c:\ in my example) and file name (abc.txt) as in your PC.

Hope it helps?

Qi
Site Addict
 
Join Date: Feb 2007
Posts: 553
#3: Sep 17 '08

re: lnk batch


Just to add that you should run the batch file in the same path where your .lnk files are or
change the folder path in wildcard e.g

dir c:\myFolder\*.lnk

Qi
Needs Regular Fix
 
Join Date: Mar 2008
Posts: 283
#4: Sep 17 '08

re: lnk batch


the solution above will give the name but not the target path and I don't think this can be done via standard command prompt

I don't have time to work it out now but a VB script would probably be best to do this and if I get a chance later I will try to work out some code for you.
Needs Regular Fix
 
Join Date: Mar 2008
Posts: 283
#5: Sep 17 '08

re: lnk batch


I have stuck together some code below , please note that there is no error checking so unless you are using this yourself you may want to add some

to use it just create a file called <something>.vbs ( with the <something> as whatever you want to call it ) and then past the code in and run it and it will generate a text file ( c:\output.txt )

it has been pieced together a bit so you may be able to tidy it up and also may want to change the formating as you require

Expand|Select|Wrap|Line Numbers
  1.  
  2. Option Explicit
  3.  
  4. Dim objShell, objFSO, objfile, fileFolder
  5. Dim desktopFolder, custFolder, extension, custfile
  6. Dim fullname, shortcut, shortTarget
  7.  
  8.  
  9. Set objShell = CreateObject("WScript.Shell")
  10. Set objFSO = CreateObject("Scripting.FileSystemObject")
  11.  
  12. Set fileFolder = objFSO.GetFolder("C:\Documents and Settings\all Users") ' folder to check 
  13. Set objFile = objFSO.CreateTextFile("c:\output.txt") ' file to output
  14.  
  15. Set desktopFolder = objFSO.GetFolder(filefolder & "\Desktop")
  16. Set custFolder = desktopFolder.Files
  17.  
  18. For Each custFile in custFolder
  19. extension = objFSO.GetExtensionName(LCase(custFile.name))
  20. If extension = "lnk" then
  21.  
  22. 'Find full path of shortcut
  23. fullname = objFSO.GetAbsolutePathName(custFile)
  24.  
  25. 'Find full path of target within shortcut
  26. 'See http://www.devguru.com/Technologies/wsh/quickref/wshshell_CreateShortcut.html
  27. 'for more information on how this works.
  28.  
  29. Set shortcut = objShell.CreateShortcut(fullname)
  30. shortTarget = shortcut.TargetPath
  31.  
  32. objfile.writeline "File : " & custfile.name & vbcrlf & "Target : " & shorttarget & vbcrlf 
  33. objfile.writeline "***********************************************************************" & vbcrlf
  34.  
  35. End If
  36.  
  37. Next
  38.  
  39. set objFile = nothing
  40.  
  41.  
Reply


Similar Microsoft Windows / Vista / XP / ME / 95 & 98 bytes