Solved

Batch editing shortcut targets

Posted on 2013-01-04
10
1,086 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 55

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

Industry Leaders: 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

When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.

729 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