1
votes

I'm trying to get the script below to produce a shortcut like this:

"C:\Program Files\Internet Explorer\iexplore.exe" http://WebApp/index.aspx

set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oUrlLink = WshShell.CreateShortcut(strDesktop & "\WebApp.url")
oUrlLink.TargetPath = ""&chr(34)& _
  "C:\Program Files\Internet Explorer\iexplore.exe" & _
   chr(34)&" http://WebApp/index.aspx"
oUrlLink.Save

but it doesn't seem to like the quotes.

I get an Invalid Syntax in URL: ""C:\Program Files\Internet Explorer\iexplore.exe" http://WebApp/index.aspx".

How can I embed a " without vbscript getting its knickers in a knot?

7

7 Answers

7
votes

This is according to Microsoft:

Set objShell = CreateObject("Wscript.Shell")
strFolder = objShell.SpecialFolders.Item("Desktop")
Set objShortcut = objShell.CreateShortcut(strFolder & "\Open Web Site.lnk")
objShortcut.TargetPath = "C:\Program Files\Internet Explorer\iexplore.exe"
objShortcut.Arguments = "http://WebApp/index.aspx"
objShortcut.Save

You have to use .lnk for the file extension, not .url as the .Arguments property is only available for .lnk

0
votes

Does this work?

oUrlLink.TargetPath = "C:\Program Files\Internet Explorer\iexplore.exe"
oUrlLink.Arguments = "http://WebApp/index.aspx"
oUrlLink.Save
0
votes

Escaping quotes in VB - always painful.

oUrlLink.TargetPath = """C:\Program Files\Internet Explorer\iexplore.exe"" http://WebApp/index.aspx"

0
votes

Have you tried this?

oUrlLink.TargetPath = chr(34) & "C:\Program Files\Internet Explorer\iexplore.exe" & _
                      chr(34) & " http://WebApp/index.aspx"

More about quoting can be found here.

0
votes

This worked for me:

set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oUrlLink = WshShell.CreateShortcut(strDesktop & "\WebApp.url")
oUrlLink.TargetPath = "C:\Program Files\Internet Explorer\iexplore.exe http://WebApp/index.aspx"
oUrlLink.Save
0
votes

Use this as the target path


"C:\Program Files\Internet Explorer\iexplore.exe http://WebApp/index.aspx"

How about this


Target= "http://WebApp/index.aspx"

0
votes
Set objShell = WScript.CreateObject("WScript.Shell" )
strDesktopFolder = objShell.SpecialFolders("Desktop") 
Set objShortCut = objShell.CreateShortcut(strDesktopFolder & "\test.lnk" ) 
objShortCut.TargetPath = "http://www.google.com/" 
objShortCut.Description = "Test Environment" 
objShortCut.Save 

The above worked fine for me for deploying shortcuts to desktops as part of a GPO. The names have been changed to protect the innocent.

Seems a bit cleaner to my mind but i'm not a script guru by any means.