On some file servers, users create multiple shotcuts pointing to different locations on the same server.
When migrating data from this server to another, these shorcuts are deprecated, so you need to update them and you can have thousands...
Here is a VB script that let you batch edit these shortcuts so that you can keep all of them updated.
Dim objFSO
Const srcServer = "\\formerServer\"
Const dstServer = "\\newServer\"
args = WScript.Arguments.Count
If args < 1 then
  WScript.Echo "usage: cscript replaceLinkTarget.vbs [folder]"
  WScript.Quit
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Call FindEditShortcut(WScript.Arguments.Item(0))
Sub FindEditShortcut(currentDrive)
  Dim objFile
  Dim objFolder
  For Each objFolder In objFSO.GetFolder(currentDrive).SubFolders   
    For Each objFile In objFolder.Files
      'Check extension
      If LCase(objFSO.GetExtensionName(objFile)) = "lnk" Then
        Set objShell = CreateObject("WScript.Shell")
        Set shortcut = objShell.CreateShortcut(objFile.path)
        target = LCase(shortcut.TargetPath)
        If (InStr(target, srcServer) > 0) Then
          target = replace(target,srcServer,dstServer)
          Wscript.Echo "New target : " & target
          shortcut.TargetPath = target
          shortcut.Save
        End If
      End If
    Next
   
    Call FindEditShortcut(objFolder)
  Next
End Sub
 
 
If you can give a working script, that would be nice.
ReplyDeleteFor example I have a folder that I want to process all .lnk files in and run this against it
Hello,
ReplyDeleteThe script is now updated.
The previous version was incomplete. Sorry about that
I'm not sure if you will see this as your script was posted in 2011. I have server changing from one IP to another, and shortcuts were used for everything. A recent search showed over 10K lnk files that need to be updated. Your program script worked AWESOME! Thank you so much, you have no idea how much time it has saved me!!!!!!
ReplyDeleteThere are a great deal of content supplier that have given you several free web content that is prepared to utilize. You don't have to pay a software engineer or website admin to get an expert site. script reader
ReplyDelete