GeorgeAdhaero
IS-IT--Management
Hi,
This is a script I use to update a shortcut argument and it works well apart from if the short cut has allready been updated the find finds the oldserver name in the new string and replaces it.
I kinda know that what I want to do is a regex match ^Oldserver so it only finds it in that format but how would I integrate this into my script ?
cheers
Dim objShell, objFSO, SearcherPath, fileFolder
Dim userFolder, desktopFolder, custFolder, extension
Dim fullname, shortcut, shortTarget
SearcherPath = "C:\Program Files\Searcher\Searcher.exe"
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set fileFolder = objFSO.GetFolder("C:\Documents and Settings")
Set subFileFolder = fileFolder.Subfolders
For Each userFolder in subFileFolder
If objFSO.FolderExists(userFolder & "\Desktop") Then
Set desktopFolder = objFSO.GetFolder(userFolder & "\Desktop")
Set custFolder = desktopFolder.Files
For Each custFile in custFolder
extension = objFSO.GetExtensionName(LCase(custFile.name))
If extension = "lnk" then
'Find full path of shortcut
fullname = objFSO.GetAbsolutePathName(custFile)
'Find full path of target within shortcut
Set shortcut = objShell.CreateShortcut(fullname)
shortTarget = shortcut.TargetPath
If InStr(shortTarget, SearcherPath) then
Dim seachershortcutfile
Set seachershortcutfile = objFSO.GetFile(fullname)
Set oWS = WScript.CreateObject("WScript.Shell")
sLinkFile = seachershortcutfile
Set oLink = oWS.CreateShortcut(sLinkFile)
sFind = "Oldserver"
sReplace = "Newserver\Oldserver"
ix = instr(oLink.Arguments, sFind)
if ix > 0 then
oLink.Arguments = left(oLink.Arguments,ix-1) & sReplace & mid(oLink.Arguments,ix+len(sFind))
oLink.Save
end if
End If
End If
Next
End If
This is a script I use to update a shortcut argument and it works well apart from if the short cut has allready been updated the find finds the oldserver name in the new string and replaces it.
I kinda know that what I want to do is a regex match ^Oldserver so it only finds it in that format but how would I integrate this into my script ?
cheers
Dim objShell, objFSO, SearcherPath, fileFolder
Dim userFolder, desktopFolder, custFolder, extension
Dim fullname, shortcut, shortTarget
SearcherPath = "C:\Program Files\Searcher\Searcher.exe"
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set fileFolder = objFSO.GetFolder("C:\Documents and Settings")
Set subFileFolder = fileFolder.Subfolders
For Each userFolder in subFileFolder
If objFSO.FolderExists(userFolder & "\Desktop") Then
Set desktopFolder = objFSO.GetFolder(userFolder & "\Desktop")
Set custFolder = desktopFolder.Files
For Each custFile in custFolder
extension = objFSO.GetExtensionName(LCase(custFile.name))
If extension = "lnk" then
'Find full path of shortcut
fullname = objFSO.GetAbsolutePathName(custFile)
'Find full path of target within shortcut
Set shortcut = objShell.CreateShortcut(fullname)
shortTarget = shortcut.TargetPath
If InStr(shortTarget, SearcherPath) then
Dim seachershortcutfile
Set seachershortcutfile = objFSO.GetFile(fullname)
Set oWS = WScript.CreateObject("WScript.Shell")
sLinkFile = seachershortcutfile
Set oLink = oWS.CreateShortcut(sLinkFile)
sFind = "Oldserver"
sReplace = "Newserver\Oldserver"
ix = instr(oLink.Arguments, sFind)
if ix > 0 then
oLink.Arguments = left(oLink.Arguments,ix-1) & sReplace & mid(oLink.Arguments,ix+len(sFind))
oLink.Save
end if
End If
End If
Next
End If