redlair2000
Technical User
Hello all,
I am trying to create a script that will find and replace a shortcut. We have recently moved a network application to another location. I need a way to find there desktop shortcut (which may be named anything) and change the target path. I put together a script with tid bits from the net. The script does not error out but does not find any shortcuts. Can you look it over and tell me if I am on the right track?
-----------------------------------------------------------
Set oNetwork = CreateObject("WScript.Network")
sTargetStrOld = "\\onsite\EPODist" & oNetwork.UserName
sTargetStrNew = "\\onsite\Images" & oNetwork.UserName
Set oShell = CreateObject("WScript.Shell")
set oFso = CreateObject("Scripting.FilesystemObject")
sPath = oShell.SpecialFolders("Desktop")
ChkLnk(sPath)
sPath = oShell.SpecialFolders("AllUsersDesktop")
ChkLnk(sPath)
Sub ChkLnk (sFolder)
Set oFolder = oFso.GetFolder(sFolder)
Set oFiles = oFolder.Files
For Each oFile In oFiles
If LCase(oFso.GetExtensionName(oFile)) = "lnk" Then
Set oLnk = oShell.CreateShortcut(oFile)
If LCase(oLnk.TargetPath) = LCase(sTargetStrOld) Then
oLnk.TargetPath = sTargetStrNew
oLnk.Save
End If
End If
Next
End Sub
msgbox "Done
I am trying to create a script that will find and replace a shortcut. We have recently moved a network application to another location. I need a way to find there desktop shortcut (which may be named anything) and change the target path. I put together a script with tid bits from the net. The script does not error out but does not find any shortcuts. Can you look it over and tell me if I am on the right track?
-----------------------------------------------------------
Set oNetwork = CreateObject("WScript.Network")
sTargetStrOld = "\\onsite\EPODist" & oNetwork.UserName
sTargetStrNew = "\\onsite\Images" & oNetwork.UserName
Set oShell = CreateObject("WScript.Shell")
set oFso = CreateObject("Scripting.FilesystemObject")
sPath = oShell.SpecialFolders("Desktop")
ChkLnk(sPath)
sPath = oShell.SpecialFolders("AllUsersDesktop")
ChkLnk(sPath)
Sub ChkLnk (sFolder)
Set oFolder = oFso.GetFolder(sFolder)
Set oFiles = oFolder.Files
For Each oFile In oFiles
If LCase(oFso.GetExtensionName(oFile)) = "lnk" Then
Set oLnk = oShell.CreateShortcut(oFile)
If LCase(oLnk.TargetPath) = LCase(sTargetStrOld) Then
oLnk.TargetPath = sTargetStrNew
oLnk.Save
End If
End If
Next
End Sub
msgbox "Done