Connecting Tech Pros Worldwide Help | Site Map

lnk batch

  #1  
Old September 16th, 2008, 08:28 PM
Newbie
 
Join Date: Sep 2008
Posts: 1
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.
  #2  
Old September 16th, 2008, 09:09 PM
Site Addict
 
Join Date: Feb 2007
Posts: 553

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
  #3  
Old September 17th, 2008, 10:47 AM
Site Addict
 
Join Date: Feb 2007
Posts: 553

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
  #4  
Old September 17th, 2008, 06:10 PM
Needs Regular Fix
 
Join Date: Mar 2008
Posts: 283

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.
  #5  
Old September 17th, 2008, 07:46 PM
Needs Regular Fix
 
Join Date: Mar 2008
Posts: 283

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 Threads
Thread Thread Starter Forum Replies Last Post
How would you go about creating a heap of shortcuts to a batch file? googleboy answers 1 September 17th, 2006 02:45 PM
Help with Batch file execution KMiller answers 0 November 22nd, 2005 04:53 PM
Help with Batch file execution KMiller answers 0 July 21st, 2005 08:56 PM