Connecting Tech Pros Worldwide Help | Site Map

lnk batch

 
LinkBack Thread Tools Search this Thread
  #1  
Old September 16th, 2008, 07:28 PM
Newbie
 
Join Date: Sep 2008
Posts: 1
Default lnk batch

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.
Reply
  #2  
Old September 16th, 2008, 08:09 PM
Site Addict
 
Join Date: Feb 2007
Posts: 552
Default

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

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

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

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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.