tags:

views:

1695

answers:

7

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?

A: 

Does this work?

oUrlLink.TargetPath = "C:\Program Files\Internet Explorer\iexplore.exe"
oUrlLink.Arguments = "http://WebApp/index.aspx"
oUrlLink.Save
schnaader
I get a Object doesn't support this property or method: 'oUrlLink.Arguments'
John Nolan
A: 

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"

Tester101
shortcut doesn't run
John Nolan
Yeah I need to enforce IE for this
John Nolan
A: 

Escaping quotes in VB - always painful.

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

Kees de Kooter
I tried this. I don't understand why it fired an error on the second pair of quotes.
Paulo Guedes
A: 

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.

Zaagmans
A: 

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
Paulo Guedes
yes but the slashes change from / to \
John Nolan
that's ok, because the shortcut will be called as file:///C:/ ... which uses the normal slash.
Paulo Guedes
+5  A: 

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

Jim H.
Ah thanks Angry Jim
John Nolan
A: 
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.