VB Script to create URL link not working
-
Wednesday, May 02, 2012 2:47 PM
Referring to the following reference:
http://support.microsoft.com/kb/244677
I have created a .vbs file as in the third example:
WshShell = CreateObject("WScript.Shell") strDesktop = WshShell.SpecialFolders("Desktop") oUrlLink = WshShell.CreateShortcut(strDesktop+"\Microsoft Web Site.URL") oUrlLink.TargetPath = "http://www.microsoft.com" oUrlLink.Save
...and I get this error:
C:\Scripts\url.vbs(1, 1) Microsoft VBScript runtime error: Object doesn't support this property or method: 'WshShell'
Anyone?
Grant Ward, a.k.a. Bigteddy
All Replies
-
Wednesday, May 02, 2012 2:54 PM
It's missing a "Set" on the creation of the shortcut object.
Set objShell = WScript.CreateObject("WScript.Shell") strDesktop = objShell.SpecialFolders("AllUsersDesktop") Set objMyShortcut = objShell.CreateShortcut(strDesktop & "\MYLINK.lnk") objMyShortcut.TargetPath = "http://www.microsoft.com" objMyShortCut.Save
Edit: Well and on the shell object as well.
Edit2: Interestingly enough, that Microsoft article is really wrong and apparently has been wrong since 2007 (according to the doc date).- Marked As Answer by BigteddyMicrosoft Community Contributor Wednesday, May 02, 2012 3:03 PM
- Edited by thepip3r Wednesday, May 02, 2012 3:04 PM
-
Wednesday, May 02, 2012 2:56 PMModerator
Hi,
VBScript requires the Set keyword in order to create an object reference (the reason for this is due to a bad design decision to allow the notion of default object properties, but I digress). Also, VBScript uses the & character to concatenate strings, not +. So the script should actually look like this:
Dim WshShell, StrDesktop, oUrlLink Set WshShell = CreateObject("WScript.Shell") strDesktop = WshShell.SpecialFolders.Item("Desktop") Set oUrlLink = WshShell.CreateShortcut(strDesktop & "\Microsoft Web Site.url") oUrlLink.TargetPath = "http://www.microsoft.com" oUrlLink.Save()Bill
- Marked As Answer by BigteddyMicrosoft Community Contributor Wednesday, May 02, 2012 3:03 PM
-
Wednesday, May 02, 2012 3:00 PMHmmm... another intersting point: despite the concatenation operator in VBS being & as Bill stated, The + does not throw an error in my code and does exactly what I want it to, where I want it to. I'm so glad to be done with VBS -- PoSh is so nice.
-
Wednesday, May 02, 2012 3:04 PMSo the MS article is wrong? Shouldn't someone say something?
Grant Ward, a.k.a. Bigteddy
-
Wednesday, May 02, 2012 3:09 PMThe MS article is really wrong. It's not properly formatted to be executed in a WSF file or a VBS. I would agree that it should be changed but have no idea who to tell or where to begin. Haha.
-
Wednesday, May 02, 2012 3:11 PM
The MS article is really wrong. It's not properly formatted to be executed in a WSF file or a VBS. I would agree that it should be changed but have no idea who to tell or where to begin. Haha.
Just post a comment at the bottom, correcting it. (You'll probably get a bronze medal)Grant Ward, a.k.a. Bigteddy
-
Wednesday, May 02, 2012 3:16 PMI submitted feedback to the article but it's not like the newer stuff where everyone can see the comment. I just submitted an anonymous message about the article but at least was potentially able to relay the message.

