Creating a shortcut on the desktop in vb.net

  • Thread starter Thread starter Paulers
  • Start date Start date
P

Paulers

I have been searching for example code that will create a shortcut
link to a file and place it on the desktop. I have searched google and
found a couple examples using the windows scripting object but they do
not seem to work for me. Would someone be kind enough to post some
example code?

thanks!
 
by the way. here is one of the examples I could not get working. vs.net
claimed there were no errors but when I tried to compile and use I got
null pointer exception

Public Function CreateShortCutOnDesktop(ByVal userID As String, _
ByVal passWord As String) As Boolean
Try
Dim DesktopDir As String = _
CType(WshShell.SpecialFolders.Item("Desktop"), String)
Dim shortCut As IWshRuntimeLibrary.IWshShortcut

' short cut files have a .lnk extension
shortCut = CType(WshShell.CreateShortcut(DesktopDir & _
"\MyNewShortcut.lnk"), _
IWshRuntimeLibrary.IWshShortcut)

' set the shortcut properties
With shortCut
.TargetPath = _

System.Reflection.Assembly.GetExecutingAssembly.Location()
.WindowStyle = 1
.Description = "Run Typist Summary"
.WorkingDirectory = DesktopDir
' the next line gets the first Icon from the executing
program
.IconLocation = _

System.Reflection.Assembly.GetExecutingAssembly.Location() & _
", 0"
' the next line sets the userID and passWord into the
shortcut
' as arguments
' which will be read from the command line.
.Arguments = userID & ", " & passWord
.Save() ' save the shortcut file
End With
Return True
Catch ex As System.Exception
' add your error handling here, if any
Return False
End Try
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top