Solved

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

Posted on 2009-05-20
11
585 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
  • 5
  • 4
  • 2
11 Comments
 
LVL 85

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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 85

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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