2011-02-04 46 views
0

我掙扎...使用谷歌,並沒有拿出這個答案!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" 

回答

2

來自MSDN上TargetPath屬性的描述(我加粗加):

此屬性僅適用於快捷方式的目標路徑。 快捷方式的任何參數都必須放置在參數的屬性中。

+0

謝謝 - 一直讓我瘋狂......我沒有意識到有一個論據的屬性......現在有道理我想到了! – 2011-02-04 16:59:42

相關問題