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.
Set oLink = WSHShell.CreateShortcut(strDirectory & "\Shortcut Text.lnk") oLink.TargetPath = ServerPath & "\ApplicationName.exe /Parameter" oLink.WorkingDirectory = ServerPath oLink.WindowStyle = 4 oLink.Save
The resulting Target:
"\\server\share\ApplicationName.exe /Parameter"
After a bit of searching, I found the line I was missing:
oLink.Arguments = "/Parameter"
The resulting code becomes:
Set oLink = WSHShell.CreateShortcut(strDirectory & "\Shortcut Text.lnk") oLink.TargetPath = ServerPath & "\ApplicationName.exe" oLink.Arguments = "/Parameter" oLink.WorkingDirectory = ServerPath oLink.WindowStyle = 4 oLink.Save
Which then gives a final Target Path of:
"\\server\share\ApplicationName.exe" /Parameter
Works like a charm.
Thanks a lot, Craig!! It was really, really useful for me.
Greetings from Rio de Janeiro, Brazil
@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?
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.
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!)
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!
Thanks a bunch, you just saved another Linux guy stuck in foreign Windows-land !
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.
Thanks a lot, saved me a lot of time.
Thanks for posting this :) … I spent an hour trying to figure out the correct syntax before reading this!
Holy Lama in Pyjama! Exactly what I need right now! Thank you!
Nice, Just what I needed to get my script to work like I want to. Thanks.
Thank you very much!
OMFG!! You rock my socks dude. I’ve been looking for something like this for almost a year!
Works perfectly!!
Thanks so much
Awesome post, this really helps a lot, thanks for sharing. cheers.