Note that there are some explanatory texts on larger screens.

plurals
  1. POVBS Using createshortcut to get the name of a shortcut with spaces
    text
    copied!<p>I'm struggling... used google and have come up with no answers to this one!</p> <p>I have a code that I'm intending to run at user logon which will find a shortcut and update the shortcut location to reflect some network changes - but the shortcut has spaces in it and VBS won't find the full target path... HELP!!!</p> <p>The current target of the shortcut is:</p> <pre><code>\\LANG-APPS2\Mandata\Warehouse\Programs\StartApp.exe /sWH /ip192.168.73.124 </code></pre> <p>But it will only return the bit up to .exe - it misses the last bit of <code>/sWH /ip192.168.73.124</code></p> <p>Here's my script:</p> <pre><code>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 &gt; 0 then srvFind = "lang-apps2\mandata\warehouse\programs\startapp.exe" srvSearch = instr(shortTarget, srvFind) if srvSearch &gt; 0 then pracFind = "Practice" pracSearch = instr(fullname, pracFind) if pracSearch &gt; 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" </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload