Deployment Solution

 View Only
  • 1.  Edit Shortcuts (lnk files)

    Posted Nov 12, 2008 03:01 PM
    We are in the process of dropping in new servers in about 80 locations. Each server will have a new name. My question is concerning shortcuts users may have on their desktops that are pointing to various documents on a network drive on the old server. Is there anyway to automate a process that can edit the .lnk file directly so that will look for the old server name and change it to the new one? Thanks!!!


  • 2.  RE: Edit Shortcuts (lnk files)

    Posted Nov 13, 2008 02:53 AM
    The easiest way to do this is building a lmhost file that resolves the new servername when the old server is queried. that works very good. You can build one lmhost file and deploy it to all clients. Regards Erik www.DinamiQs.com


  • 3.  RE: Edit Shortcuts (lnk files)

    Posted Feb 27, 2009 01:14 PM

    I've gone through and utilized the Site entry on computers before, then used %SITE% to build shortcuts. While I don't know of a good way to update existing ones, you could create some new ones on-the-fly pretty easy with a script like this:

    http://www.altirigos.com/repository/getfile.php?id=108



  • 4.  RE: Edit Shortcuts (lnk files)

    Posted Mar 03, 2009 09:37 PM

     I wouldn't script it but here you have something to work with.

    <pre>

    Dim SearchFor : SearchFor = "\\OldServerName\"

    Dim ReplaceWith : ReplaceWith = "\\NewServerName\"


    Dim DirectoryPath : DirectoryPath = GetSpecialFolderPath("Desktop")

    'Dim DirectoryPath : DirectoryPath = GetSpecialFolderPath("AllUsersDesktop")


    EnumFolder DirectoryPath


    Sub EnumFolder(DirectoryPath)

    Dim FSO, Folder, Files, File, ShortcutPath, ShortcutTargetPath

    Set FSO = CreateObject("Scripting.FileSystemObject")

    If NOT FSO.FolderExists(DirectoryPath) Then Exit Sub

    Set Folder = FSO.GetFolder(DirectoryPath) : Set Files = Folder.Files

    For Each File in Files

    If IsShortcut(File.Path) Then

    ShortcutPath = File.Path

    ShortcutTargetPath = GetShortcutTargetPath(File.Path)

    If ValueMatchesSearchPattern(ShortcutTargetPath, SearchFor) Then

    ShortcutTargetPath = GetNewShortcutTargetPath(ShortcutTargetPath)

    Call SetShortcutTargetPath(ShortcutPath, ShortcutTargetPath)

    End If

    End If

    Next

    Set File = Nothing

    Set Files = Nothing

    Set Folder = Nothing

    Set FSO = Nothing

    End Sub


    Function ValueMatchesSearchPattern(SearchValue, SearchPattern)

    Dim i

    ValueMatchesSearchPattern = False

    If Instr(1, SearchValue, SearchPattern, 1) > 0 Then

    ValueMatchesSearchPattern = True

    End If

    End Function


    Function GetNewShortcutTargetPath(ShortcutTargetPath)

    GetNewShortcutTargetPath = Replace(ShortcutTargetPath, SearchFor, ReplaceWith, 1, 1, 1)

    End Function


    Function IsShortcut(FilePath)

    Dim FileExtension

    IsShortcut = False

    FileExtension = UCase(Mid(FilePath, InStrRev(FilePath, ".")+1))

    If "LNK" = FileExtension Then IsShortcut = True

    End Function


    Function GetSpecialFolderPath(SpecialFolder)

    Dim WshShell

    Set WshShell = CreateObject("WScript.Shell")

    GetSpecialFolderPath = WshShell.SpecialFolders(SpecialFolder)

    Set WshShell = Nothing

    End Function


    Function GetShortcutTargetPath(ShortcutPath)

    Dim WshShell, Shortcut

    Set WshShell = CreateObject("WScript.Shell")

    Set Shortcut = WshShell.CreateShortcut(ShortcutPath)

    GetShortcutTargetPath = Shortcut.TargetPath

    Set Shortcut = Nothing

    Set WshShell = Nothing

    End Function


    Function SetShortcutTargetPath(ShortcutPath, ShortcutTargetPath)

    Dim WshShell, Shortcut

    Set WshShell = CreateObject("WScript.Shell")

    Set Shortcut = WshShell.CreateShortcut(ShortcutPath)

    Shortcut.TargetPath = ShortcutTargetPath

    Shortcut.Save

    Set Shortcut = Nothing

    Set WshShell = Nothing

    End Function

     

    </pre>