views:

703

answers:

2

Problem: There are a bunch of .lnk files on C drive that point to the J: drive, but the J: drive is gone 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.

Question: 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:/* ? If yes, please share some tips on how you'd 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 gotta be a better way" type questions.

+1  A: 

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
+1  A: 

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