VBScript – Create a shortcut with parameters

Hi,

This really is something quite simple, but it has taken me ages to find the answer. And it seems to be something that many people are looking for the answer to and not finding easily.

I wanted to create a shortcut using a VBScript, part of an installation script. The program had parameters passed after it with spaces inbetween.

I could create the shortcut, no problem using the code below, but whenever I checked the shortcut, it didn’t work. Windows was putting quotes around the target, meaning the parameters were being passed as part of the path.

The resulting Target:

After a bit of searching, I found the line I was missing:

The resulting code becomes:

Which then gives a final Target Path of:

 Works like a charm.

22 people found this post useful.


14 thoughts on “VBScript – Create a shortcut with parameters

  1. Thanks a lot, Craig!! It was really, really useful for me.
    Greetings from Rio de Janeiro, Brazil

  2. @echo off
    Cls
    set SCRIPT=”%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs”
    echo Set oWS = WScript.CreateObject(“WScript.Shell”) >> %SCRIPT%
    echo sLinkFile = “%USERPROFILE%\Desktop\Creative Cloud.lnk” >> %SCRIPT%
    echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
    echo oLink.TargetPath = “C:\Windows\system32\runas.exe” >> %SCRIPT%
    echo oLink.Arguments = “/user:HOSTNAME\Administrator /savecred “C:\Program Files (x86)\Adobe\Adobe Creative Cloud\ACC\Creative Cloud”” >> %SCRIPT%
    echo oLink.Save >> %SCRIPT%
    cscript /nologo %SCRIPT%
    del %SCRIPT%
    pause

    I need the above code to work, I’ve tried it a few ways but none of them have worked due to the ” ending the script prematurely. Anyone know of a way to do this how I am wanting to do this?

    1. You are missing some double quotes to escape the path in line 8. The code below works for me:

      This only works in CMD though, and will fail if you run from the PowerShell console.

  3. Thank you so much for your post! I have spent all day trying to get my shortcut argument working properly! What was tripping me up was I forgot the put a “s” at the end of oLink.Arguments (was oLink.Argument and now its oLink.Arguments).

    Hope that helps someone like me who is still very new scripting (the joys of SCCM!)

  4. Thank you so much! This saved me even more hours messing about escaping double quotes etc. Wish I’d though to google it ages ago!

  5. Nice post. I’m a Linux Sys Admin. But I was needing that and I had no idea how to do it. It Saved me a lof of time. Thanks.

  6. Thanks for posting this :) … I spent an hour trying to figure out the correct syntax before reading this!

  7. OMFG!! You rock my socks dude. I’ve been looking for something like this for almost a year!

    Works perfectly!!

    Thanks so much

Leave a Reply to ronjonp Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.