VBS script for bulk replacement shortcut destination path _vbs

Source: Internet
Author: User
You can replace all shortcuts under the specified directory and its subdirectories, specify the path to hold the shortcut, the string to be replaced, and the string you want to replace, and then double-click to run it.

Here is the code, not very complicated,:

Copy Code code as follows:
On Error Resume Next
' Replace the pointing path for all shortcuts under a folder and its subfolders

Strfolderpath= the path to the "D:\Program files\truelaunchbar\shortcut\file\ Style" shortcut
Strtoreplace= "\software\" ' Ring string
Strreplace= "\[software]\" replaced by a string

Set WshShell = CreateObject ("Shell.Application")
Set Wshfso = CreateObject ("Scripting.FileSystemObject")

Altersubfolders Wshfso.getfolder (Strfolderpath)

Sub altersubfolders (Folder)

Set Npfolder = Wshshell.namespace (Folder.path)
Set Allfiles=folder.files

For each lnkfile in Allfiles
' WScript.Echo Lnkfile.name
If InStrRev (UCase (Lnkfile.name), ". LNK ") <> 0 Then ' extension shortcuts
Set Lnkitem = Npfolder.parsename (lnkfile.name)
Set Lnkitemlink = Lnkitem.getlink
' WScript.Echo ' "" &lnkItemLink.Path& "" "
Lnkitemlink.path = Replace ("" "& Lnkitemlink.path &" "", Strtoreplace,strreplace)
Lnkitemlink.workingdirectory = Replace ("" "& Lnkitemlink.workingdirectory &" "", Strtoreplace,strreplace)
Lnkitemlink.save ()
End If
Next

For each subfolder in Folder.subfolders
' WScript.Echo ' Folder ' & Subfolder.path
Set Npfolder = Wshshell.namespace (Subfolder.path)
Set objfolder = Wshfso.getfolder (Subfolder.path)
Set allfiles = Objfolder.files

For each lnkfile in Allfiles
If InStrRev (UCase (Lnkfile.name), ". LNK ") <> 0 Then ' extension shortcuts
Set Lnkitem = Npfolder.parsename (lnkfile.name)
Set Lnkitemlink = Lnkitem.getlink
' WScript.Echo ' "" &lnkItemLink.Path& "" "
Lnkitemlink.path = Replace ("" "& Lnkitemlink.path &" "", Strtoreplace,strreplace)
Lnkitemlink.workingdirectory = Replace ("" "& Lnkitemlink.workingdirectory &" "", Strtoreplace,strreplace)
Lnkitemlink.save ()
End If
Next

Altersubfolders subfolder

Next
End Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.