Modify a vb script to change the targets in lnk files
greetings,
i`m using the following vb script over the "send as" menu to change the two targets inside lnk files (static drive letter to unc path). how can i modify the script to search lnk files in subfolders too? is there an easy way to modify the script for a recursive search in subfolders without changing the basement and the design of the script?
On Error Resume Next
set WshShell = WScript.CreateObject("WScript.Shell")
set fso = CreateObject("Scripting.FileSystemObject")
set objArgs = WScript.Arguments
set fld = fso.GetFolder(objArgs(0))
set fc = fld.Files
For Each f1 in fc
If UCase(Right(f1.name, 3)) = "LNK" Then
Set sl = WshShell.CreateShortcut(f1.Path)
z = sl.TargetPath
z = Replace(z, "S:\", "\\server\data\")
sl.TargetPath = z
y = sl.WorkingDirectory
y = Replace(y, "S:\", "\\server\data\")
sl.WorkingDirectory = y
sl.Save
Username = WshShell.ExpandEnvironmentStrings("%USERNAME%")
x = sl.TargetPath
x = Replace(x, "P:\", "\\server\redirected\%username%\documents\personal\")
sl.TargetPath = x
w = sl.WorkingDirectory
w = Replace(w, "P:\", "\\server\redirected\" & createobject("wscript.shell").expandenvironmentstrings("%username%") & "\documents\personal\")
sl.WorkingDirectory = w
sl.Save
End If
Next
WScript.Echo "done!"
thanks for your help.
i`m using the following vb script over the "send as" menu to change the two targets inside lnk files (static drive letter to unc path). how can i modify the script to search lnk files in subfolders too? is there an easy way to modify the script for a recursive search in subfolders without changing the basement and the design of the script?
On Error Resume Next
set WshShell = WScript.CreateObject("WScript.Shell")
set fso = CreateObject("Scripting.FileSystemObject")
set objArgs = WScript.Arguments
set fld = fso.GetFolder(objArgs(0))
set fc = fld.Files
For Each f1 in fc
If UCase(Right(f1.name, 3)) = "LNK" Then
Set sl = WshShell.CreateShortcut(f1.Path)
z = sl.TargetPath
z = Replace(z, "S:\", "\\server\data\")
sl.TargetPath = z
y = sl.WorkingDirectory
y = Replace(y, "S:\", "\\server\data\")
sl.WorkingDirectory = y
sl.Save
Username = WshShell.ExpandEnvironmentStrings("%USERNAME%")
x = sl.TargetPath
x = Replace(x, "P:\", "\\server\redirected\%username%\documents\personal\")
sl.TargetPath = x
w = sl.WorkingDirectory
w = Replace(w, "P:\", "\\server\redirected\" & createobject("wscript.shell").expandenvironmentstrings("%username%") & "\documents\personal\")
sl.WorkingDirectory = w
sl.Save
End If
Next
WScript.Echo "done!"
thanks for your help.
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 348344
Url: https://administrator.de/forum/modify-a-vb-script-to-change-the-targets-in-lnk-files-348344.html
Ausgedruckt am: 04.05.2025 um 09:05 Uhr
2 Kommentare
Neuester Kommentar

Hi there,
our search gives you all answers
, here is your code for searching subfolders for lnk files
Mehrere Verzeichnisse in einen Script angeben
A simple sub wich calls itsself for all folders and subfolders.
Regards
our search gives you all answers
Mehrere Verzeichnisse in einen Script angeben
A simple sub wich calls itsself for all folders and subfolders.
Regards

Don't forget Wie kann ich einen Beitrag als gelöst markieren? please, thanks.