0

I'm trying to write a script that will update desktop shortcuts in WinXP and Win7 (32 and 64bit). I'm having 2 problems, in XP, the target path of the shortcut won't change, and in both XP and 7, the "Start In" part of the shortcut won't change. Whats wrong here and how can I correct?

If InStr(GetWindowsVer(), "XP") > 0 then
    IterateFolder("C:\Documents and Settings\")
Elseif InStr(GetWindowsVer(), "7") > 0 then
    IterateFolder("C:\Users\")
End if

Sub IterateFolder(folderPath)
    Dim strFolderToSearch, objFSO, objRootFolder, objFolder, colSubfolders, strOutput, subFolder
    strFolderToSearch = folderPath

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objRootFolder = objFSO.GetFolder(strFolderToSearch)
    Set colSubfolders = objRootFolder.SubFolders

    For Each objFolder in colSubfolders

            subFolder = objFolder.Path & "\Desktop"

            Set objFSO1 = CreateObject("Scripting.FileSystemObject")
            Set objFolder1 = objFSO.GetFolder(subFolder)

            Set colFiles = objFolder1.Files
            For Each objFile in colFiles
            If strcomp(right(objFile.name,4),".lnk",vbTexctCompare) = 0 then                

                Set Shell = CreateObject("WScript.Shell")
                Set Link = Shell.CreateShortcut(objFile.Path)

                if instr(Link.TargetPath, "Office") > 0 then
                    strOutput = objFile.Path
                    strOutput = strOutput & vbCr & vbLf & Link.TargetPath
                    strOutput = strOutput & vbCr & vbLf & Link.WorkingDirectory
                    MsgBox strOutput     'This line returns expected data'

                    Link.TargetPath = Replace(Link.TargetPath, "Office11", "Office14"

                    if GetBits = "64" Then
                        Link.TargetPath = Replace(Link.TargetPath, "Program Files\", "Program Files (x86)\")
                    End if

                    Link.WorkingDirectory = Replace(Link.WorkingDirectory, "Office11", "Office14")
                    Link.Save

                End if
            End if
        Next
    Next
End Sub 
4

1 回答 1

0

代码完全按照我说的做,vbs Replace 函数中使用的默认比较方法是二进制,区分大小写。由于某些原因,快捷方式中的路径不区分大小写。我通过添加> , 1, -1, 1到替换语句的末尾添加了执行 vbTextCompare 的选项,因此它们现在看起来像这样:

Link.TargetPath = Replace(Link.TargetPath, "Office14", "Office99", 1, -1, 1)

因此,它现在将 Office14 替换为 Office99,而不考虑大小写。我在 XP 中的目标路径和 7 中的 WorkingDirectory 现在都在改变!

于 2013-05-02T15:14:42.470 回答