AllExperts > VB Script 
Search      
VB Script
Volunteer
Answers to thousands of questions
 Home · More VB Script Questions · Answer Library  · Encyclopedia ·
More VB Script Answers
Question Library

Ask a question about VB Script
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Subbu
Expertise
I can answer VB Script questions which are related to Visual Basic / VBA / QTP Scripts.

Experience
8 Years

Education/Credentials
Master of Computer Applications

Awards and Honors
Established Member from QA Forums and Brainbench certification

 
   

You are here:  Experts > Computing/Technology > Basic > VB Script > internet shortcut in program subfolder.

VB Script - internet shortcut in program subfolder.


Expert: Subbu - 4/18/2009

Question
QUESTION: Thanks for helping out. I am able to create an internet shortcut to the desktop via available vbscript but haven't been able to figure out how to create this in a program files subfolder. Here's the code I am using to create one on the desktop. Thanks again for your help. Alan

set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oUrlLink = WshShell.CreateShortcut(strDesktop & "\Setup.url")
oUrlLink.TargetPath = "http://www.clnmnd.com"
oUrlLink.Save

ANSWER: Hi Alan,

can you email me value of strDesktop variable has.

If it is this
C:\windows\desktop

then use this code
set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oUrlLink = WshShell.CreateShortcut(mid(strdesktop,1,instr(1,strdesktop,"\"))&"Program Files" & "\Setup.url")
oUrlLink.TargetPath = "http://www.clnmnd.com"
oUrlLink.Save

Let me know if you have any issues.

---------- FOLLOW-UP ----------

QUESTION: Thanks
This is going to be part of nested build that will be used on vista and xp so there are different paths to the desktop. I ended up with this work around that copies the shortcut to the program subfolder. However, I get an error message when the shortcut already exists. Is there another way to write this besides 'on error resume next' to avoid the error. Thanks your help and time are very much appreciated.

on error resume next
If not filesys.FileExists("c:\program files\myinstallfolder\tutorial\tutorial.html") Then

  filesys.MoveFile shortcut, "c:\program files\myinstallfolder\tutorial\"


Answer
Yes, You can handle any kind of error.

First find out what is the error number you are getting(Here i am assuming 1234).

Private Sub CopyShortCut()
on error goto err_CopyShortCut

' your code here
' your code here
' your code here


exit_CopyShortCut:
  exit Sub

err_CopyShortCut:
  if err.Number = 1234 'Shortcut already exists
      goto exit_CopyShortCut 'Ignore this error
  else
      msgbox err.Description
      goto exit_CopyShortCut
  end if
End Sub

Let me know for any need.  

Subbu.

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.