VBS使用createshortcut获取空格的快捷方式的名称

问题描述:

我挣扎...使用谷歌,并没有拿出这个答案!VBS使用createshortcut获取空格的快捷方式的名称

我有一个代码,我打算在用户登录时运行,它将找到一个快捷方式并更新快捷方式位置以反映一些网络更改 - 但快捷方式中有空格,VBS将无法找到完整目标路径...帮助!

快捷的当前目标是:

\\LANG-APPS2\Mandata\Warehouse\Programs\StartApp.exe /sWH /ip192.168.73.124 

但它只会返回位达.EXE - 它忽略的/sWH /ip192.168.73.124

这里的最后一位是我的脚本:

On Error Resume Next 

    wscript.echo "Checking Warehouse Shortcut..." 
    Dim fso, folder, files, sFolder 
    Set fso = CreateObject("Scripting.FileSystemObject") 
    Set Shell = CreateObject("WScript.Shell") 
    sFolder = Shell.SpecialFolders("Desktop") 
    Set folder = fso.GetFolder(sFolder) 
    Set files = folder.Files 

    For each folderIdx In files 
     fullname = fso.GetAbsolutePathName(folderIdx) 
     Set shortcut = Shell.CreateShortcut(fullname) 
     shortTarget = LCase(shortcut.TargetPath) 
     shortWorkPath = shortcut.WorkingDirectory 

     lnkFind = ".lnk" 
     lnkSearch = instr(fullname, lnkfind) 
     if lnkSearch > 0 then 

      srvFind = "lang-apps2\mandata\warehouse\programs\startapp.exe" 
      srvSearch = instr(shortTarget, srvFind) 
      if srvSearch > 0 then 

       pracFind = "Practice" 
       pracSearch = instr(fullname, pracFind) 
       if pracSearch > 0 then 

        wscript.echo "Warehouse Practice Shortcut Needs Updating!" 
        wscript.echo "Please wait while I sort that out for you......" 
        shortcut.TargetPath = """\\Lang-man\Warehouse\Programs\StartApp.exe /sWHPRAC /ip192.168.73.134""" 
        shortcut.WorkingDirectory = "\\Lang-man\Warehouse\Programs" 
        shortcut.save 
        wscript.echo "Warehouse Practice Shortcut Updated!" 
       else 

        wscript.echo "Warehouse Live Shortcut Needs Updating!" 
        wscript.echo "Please wait while I sort that out for you......" 
        shortcut.TargetPath = """\\Lang-man\Warehouse\Programs\StartApp.exe /sWH /ip192.168.73.134""" 
        shortcut.WorkingDirectory = "\\Lang-man\Warehouse\Programs" 
        shortcut.save 
        wscript.echo "Warehouse Live Shortcut Updated!" 
       end if 
      end if 
     end if 

     set shortTarget=nothing 
     set shortWorkPath=nothing 
     set shortcut=nothing 
    next 
    wscript.echo "Finished" 

来自MSDN上TargetPath属性的描述(我加粗加):

此属性仅适用于快捷方式的目标路径。 快捷方式的任何参数都必须放置在参数的属性中。

+0

谢谢 - 一直让我疯狂......我没有意识到有一个论据的属性......现在有道理我想到了! – 2011-02-04 16:59:42