469,609 Members | 1,455 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Creating a shortcut on the desktop in vb.net

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!

Jan 19 '06 #1
1 2456
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.Lo cation()
.WindowStyle = 1
.Description = "Run Typist Summary"
.WorkingDirectory = DesktopDir
' the next line gets the first Icon from the executing
program
.IconLocation = _

System.Reflection.Assembly.GetExecutingAssembly.Lo cation() & _
", 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

Jan 19 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Roy G. Vervoort | last post: by
4 posts views Thread by NaterPotater | last post: by
3 posts views Thread by Marius Rus | last post: by
4 posts views Thread by I_AM_DON_AND_YOU? | last post: by
15 posts views Thread by Mike Driscoll | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.