Solved

how can I create a shortcut in vb.net 2008 express

Posted on 2009-05-20
11
587 Views
Last Modified: 2012-06-22
I have surfed the web for code on creating shortcuts in vb.net but none of them seem to work for me
I always get this "object required error" even though I added the referance and the imports statement probably because I am using vb.net I have included the code
Imports IWshRuntimeLibrary
 
Step 5. Add the following function to your class:
 
 
CODE
Private Function CreateShortCut(ByVal shortcutName As String, ByVal creationDir As String, ByVal targetFullpath As String, ByVal workingDir As String, ByVal iconFile As String, ByVal iconNumber As Integer) As Boolean
  Try
    If Not IO.Directory.Exists(creationDir) Then
      Dim retVal As DialogResult = MsgBox(creationdir & " does not exist. Do you wish to create it?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo)
      If retVal = DialogResult.Yes
        IO.Directory.CreateDirectory(creationDir)
      Else
        Return False
      End If
    End If
 
    Dim shortCut As IWshRuntimeLibrary.IWshShortcut
    shortCut = CType(wShell.CreateShortcut(creationDir & "\" & shortcutName & ".lnk"), IWshRuntimeLibrary.IWshShortcut)
    shortCut.TargetPath = targetFullpath
    shortCut.WindowStyle = 1
    shortCut.Description = shortcutName
    shortCut.WorkingDirectory = workingDir
    shortCut.IconLocation = iconFile & ", " & iconNumber
    shortCut.Save()
    Return True
  Catch ex As System.Exception
    Return False
  End Try
End Function

Open in new window

0
Comment
Question by:Dov_B
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 350 total points
ID: 24435913
You're missing a line of code in your function:

   Dim wShell As New WshShellClass ' <--- ADD THIS LINE
   Dim shortCut As IWshRuntimeLibrary.IWshShortcut
   ShortCut = CType(wShell.CreateShortcut(creationDir & "\" & shortcutName & ".lnk"), IWshRuntimeLibrary.IWshShortcut)
    shortCut.TargetPath = targetFullpath
0
 
LVL 4

Expert Comment

by:RamanaChoudary
ID: 24435920
Imports IWshRuntimeLibrary

Private Function CreateShortCut(ByVal shortcutName As String, ByVal creationDir As String, ByVal targetFullpath As String, ByVal workingDir As String, ByVal iconFile As String, ByVal iconNumber As Integer) As Boolean
  Try
    If Not IO.Directory.Exists(creationDir) Then
      Dim retVal As DialogResult = MsgBox(creationdir & " does not exist. Do you wish to create it?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo)
      If retVal = DialogResult.Yes
        IO.Directory.CreateDirectory(creationDir)
      Else
        Return False
      End If
    End If

    Dim shortCut As IWshRuntimeLibrary.IWshShortcut
    shortCut = CType(wShell.CreateShortcut(creationDir & "\" & shortcutName & ".lnk"), IWshRuntimeLibrary.IWshShortcut)
    shortCut.TargetPath = targetFullpath
    shortCut.WindowStyle = 1
    shortCut.Description = shortcutName
    shortCut.WorkingDirectory = workingDir
    shortCut.IconLocation = iconFile & ", " & iconNumber
    shortCut.Save()
    Return True
  Catch ex As System.Exception
    Return False
  End Try
End Function
0
 
LVL 4

Expert Comment

by:RamanaChoudary
ID: 24435922
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24436002
@RamanaChoudary...the code and link you posted are also MISSING the line I mentioned above...   =\

Here it is again:

    Dim wShell As New WshShellClass ' <--- ADD THIS LINE
0
 
LVL 4

Expert Comment

by:RamanaChoudary
ID: 24436029
thanks Idle_Mind
0
 

Author Comment

by:Dov_B
ID: 24436087
thank you Idlemind and RamanaChoud
I actualy tried Idleminds correction and that got rid of the error
but I still have one problem this code is not mine and I dont understand
the different pieces of info I have to give this function
what is the
shortcutName As String
 creationDir As String,
workingDir As String,
and can I just get rid of the iconfile and iconnumber since I dont know how to get an Icon or perhaps you can tell me how to get on
0
 

Author Comment

by:Dov_B
ID: 24436156
Dear Idlemind and RamanaChoud I think I posted in the middle of your posts could you check my questions above
0
 
LVL 4

Assisted Solution

by:RamanaChoudary
RamanaChoudary earned 150 total points
ID: 24436173
- shortCutName : The name of the shortcut
- creationDir : The folder where the shortcut should be created
- workingDir : The folder to use as working directory for the target of the shortcut
0
 
LVL 4

Expert Comment

by:RamanaChoudary
ID: 24436183
refer that above link
u can see on bottom of page example too.
how to call above function
0
 

Author Comment

by:Dov_B
ID: 24436568
here is a question
I am having problems running my vb apps from other vb apps because I never know where vb.net is going to install them
so I figured I would have my vb app 1 create a shortcut in the C:\ directory as soon as it runs the first time then I know how to call it fom vb app2 with the following code

System.Diagnostics.Process.Start ("c:\vb app 1 shortcut")
can you give me a hand using the above function to create a shortcut in the C:\ directory when say the form loads
0
 

Author Closing Comment

by:Dov_B
ID: 31583697
dear Idlemind I am having the darndest time trying to run 1 vb.net application from a second vb.net application I just used this program to create a shortcut which I call from a different vb.net app using System.Diagnostics.Process.Start ("c:\newshortcut") and nothing happens
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error message when using PrintSocket.Send 7 27
DataGridView / get bound table name? 8 36
ASP.NET Calendar Control 5 29
Asp.Net Session Question 2 36
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question