Solved

Batch editing shortcut targets

Posted on 2013-01-04
10
1,047 Views
Last Modified: 2013-01-05
Running Windows 7 Professional SP-1, I have just converted over a thousand .wps files to .docx.   However, now there are hundreds of shorcuts, in myriad folders, which point to non-existent .wps files.  I would like to batch edit these links, to point them to the new .docx files.  The application which I usually rely upon, Shortcut Doctor, is not performing, for some reason.  It finds all the references to .wps in shortcut links, but will not change them to .docx (it doesn't find them again, during the Replace process, although it found them during the Search process).  Is there an application or a script which I can use, which will locate all these shortcuts and update them?
0
Comment
Question by:ddantes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 9

Accepted Solution

by:
shorvath earned 375 total points
ID: 38746005
try this:

'References:
'Microsoft Shell Controls And Automation
'Microsoft Scripting Runtime
'Windows Script Host Object Model


Dim oWsShell As New WshShell
Dim oShell  As Shell32.Shell
Dim oFolder As Shell32.Folder
Dim oFolderItems As Shell32.FolderItems
Dim FSO As New FileSystemObject
Dim oShtCut As Object
Dim LinkPath As String

LinkPath = "C:\Temp"  'set to your links path

Set oShell = New Shell32.Shell
Set oFolder = oShell.NameSpace(LinkPath)
Set oFolderItems = oFolder.Items

For Each Item In oFolderItems
   If Item.IsLink = True Then
      Set oShtCut = oWsShell.CreateShortcut(LinkPath & "\" & Item.Name & ".lnk")
      If InStr(1, oShtCut.TargetPath, ".wps") > 0 Then
         oShtCut.TargetPath = Replace(oShtCut.TargetPath, ".wps", ".docx")
         oShtCut.Save
         FSO.MoveFile oShtCut.FullName, Replace(oShtCut.FullName, ".wps", ".docx")
      End If
   End If
Next

Set oShtCut = Nothing
Set oFolderItems = Nothing
Set oFolder = Nothing
Set oShell = Nothing
Set FSO = Nothing

Open in new window

0
 

Author Comment

by:ddantes
ID: 38746032
Thank you for that script.  Sorry for my ignorance, but how should I apply that?  In other words, what is needed in order to execute that?
0
 

Author Comment

by:ddantes
ID: 38746108
I think I found out how to run the script.  I get this error:
(7, 14) Microsoft VBScript compilation error: Expected end of statement
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 125 total points
ID: 38746539
Hi, the code Shorvath posted is VBA, not pure VBScript.  You appear to have created a VBS file to run the code, hence the error.

To run the code, launch Excel, and open the code editor (ALT + F11). Insert a new module, and paste the code into it, then add the references noted at the top via Tool --> References, and run the code.

Regards,

Rob.
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 38746820
Are these LNK files that you need to update?

Do you want the script to only process the files in a specified folder, or do you want it to search all subfolders as well?

Do you want it to verify that the target file (with the WPS extension) exists before the change, and only update the link if true?

~bp
0
 
LVL 9

Expert Comment

by:shorvath
ID: 38746906
Sorry, but I saw this question under the VB Classic Group.   I did run this with VB6 and it worked.  It did rename the Target File in the .lnk file, and then renamed the Shortcut itself to reflect the new file name. I did assume that the Target path of the file and the file name has NOT changed, only the extension. ( .wps to .docx)  I will be back at work next week to test it under Windows 7, VB script, but the logic is sound and working.
0
 

Author Comment

by:ddantes
ID: 38747534
Rob:  Thank you for your instructions.  I pasted the code into a new Excel module, added the Refererences, but I don't know how to run it.  When I select "Run", it asks for a macro name.
0
 

Author Comment

by:ddantes
ID: 38747642
Never mind, I worked it out.  Thank you for the code and implementation instructions -- works like a charm!
0
 

Author Comment

by:ddantes
ID: 38747655
(Deleted)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question