|
This script was written to modify links on the server when a drive letter was changed. However, with some simple modifications, it can be updated to work as a logon script and run silently without notifying the user.
Script Code:
'Author: Carlton Colter
Option Explicit
'Globals
Dim fso
Dim ws
Set fso = CreateObject("Scripting.FileSystemObject")
set ws=wscript.createobject("wscript.shell")
Sub ChangeLink (filename, textr, textw)
Dim Replacement
Dim TheLink
Set TheLink = ws.CreateShortcut(filename)
'Replace the Target
Replacement = Replace(TheLink.TargetPath, textr, textw, 1, -1, 1)
TheLink.TargetPath = Replacement
'Replace the Startup
if Len(TheLink.WorkingDirectory)>2 then
Replacement = Replace(TheLink.WorkingDirectory, textr, textw, 1, -1, 1)
TheLink.WorkingDirectory = Replacement
end if
TheLink.Save
Set TheLink = nothing
End Sub
Sub FindLinks (foldername, find, replace)
Dim mfolder
set mfolder = fso.GetFolder(foldername)
'For Each Folder do...
Dim sfolders
set sfolders = mfolder.SubFolders
Dim objfolder
For Each objfolder in sfolders
FindLinks objfolder.Path, find, replace
Next
'For Each File do...
Dim sfiles
Set sfiles = mfolder.Files
Dim objfile
For Each objfile in sfiles
if Ucase(Right(objfile.ShortName,3)) = "LNK" then
ChangeLink objfile, find, replace
end if
Next
'Clear used vars
Set mfolder = nothing
Set sfolder = nothing
Set sfiles = nothing
End Sub
Dim SearchFolder
Dim LookFor
Dim ChangeTo
SearchFolder = InputBox("Please enter the folder you want to search: ", "SEARCH FOLDER")
LookFor = InputBox("Please enter the text you want to replace in each link: ", "TEXT TO REPLACE")
ChangeTo = InputBox("Please enter what you would like to replace the text with: ", "REPLACE WITH")
if (Len(SearchFolder)=0 OR Len(LookFor)=0 OR Len(ChangeTo)=0) Then
Wscript.Echo "Cancelled"
Wscript.quit 0
end if
FindLinks SearchFolder, LookFor, ChangeTo
'Let them know it finished.
Wscript.Echo "Finished!"
|
0 Comments