3

Problem: There are a bunch of .lnk files on the C drive that point to the J: drive, but the J: drive is gone, and the P: drive has replaced it. Various tricks have been done to get the .lnk files to still work anyway, but it's getting annoying, and it's time to just fix the things.

Using Ruby, Python, WSH.JScript or Perl, can you iterate through an entire directory tree of .lnk files and change them so they point to p:/* instead of j:/*? How would you go about it?

Note: This is not a total unknown to me, but I ask the question anyway because the API for managing .lnk files in the ways I've found so far seem too cumbersome to be the best known way of doing this. This is one of those desparate "there's got to be a better way" type questions.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dreftymac
  • 31,404
  • 26
  • 119
  • 182
  • 1
    You mention that you've found a "cumbersome way"; could you elaborate on that way? I'm guessing you're referring to instantiating IShellLink objects and calling IShellLink::SetPath? – reuben Dec 29 '08 at 06:22

3 Answers3

5

In the WindowsNT Resource Kit there's a command line utility called Shortcut.exe that I'm reliably informed will run under XP/2000/2003 as well. You can use a variety of command line switches to modify existing LNK files to point to new shortcuts.

I found information about it here: http://www.ss64.com/nt/shortcut.html

I daresay it can't be too hard to hunt down the WindowsNT Resource Kit on the Microsoft Website and extract it. It's a command line utility, so you should be able to batch it to loop through all the LNK files and modify them so they're correct.

BenAlabaster
  • 39,070
  • 21
  • 110
  • 151
2

We found this VB Script which works fine.

http://www.enterpriseitplanet.com/resources/scripts_win/article.php/3081941

Some warnings:

Careful! It runs from the root of the drive. If you test it on your own machine, you risk remapping all your Windows shortcuts - eg. those on your Start Menu! We edited the script slightly to get a bit more control (within the Main() method):

   dim onlyFolder
    Set onlyFolder =fso.GetFolder("C:\") 
    SearchFolder onlyFolder

'   for each aDrive in fso.Drives       
'       if aDrive.DriveType = 2 then
'           SearchFolder aDrive.RootFolder
'       end if
'   next

The fixlinks.ini file doesn't like empty lines, it has to be an even number of lines.

It runs in the background and may pop up permission errors for difficult directories. It's difficult to tell when it has finished, except for the confirmation window at the end. Probably best to keep an eye on it in Process Explorer, and run it from a command shell as Administrator on Vista/etc.

Other than that, worked great!

Program.X
  • 7,250
  • 12
  • 49
  • 83
2

Simply use lnk file parser at J.A.F.A.T. Archive of Forensics Analysis Tools project.

See lnk-parse-1.0.pl at http://jafat.sourceforge.net

There seems no have no dependencies (and notably not awful Windows material). Syntax is simple and link file becomes a simple text in standard output.

MUY Belgium
  • 2,330
  • 4
  • 30
  • 46
  • This program compile during 10ms and can process only one lnk per compilation. It is using constant file handler (FH instead of $fh). – MUY Belgium Dec 05 '13 at 13:35