Solved

Batch editing shortcut targets

Posted on 2013-01-04
10
994 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
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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 51

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now