Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to create a shortcut to a folder programmatically from VB.NET

310 views
Skip to first unread message

dev guy

unread,
Nov 23, 2004, 1:01:29 AM11/23/04
to
hi

how to create a shortcut to a folder programmatically from VB.NET?

regards,


Sudhakar Sadasivuni[mvp]

unread,
Nov 29, 2004, 7:33:04 AM11/29/04
to
Yes, via Windows Script Shell (WSH) api, you can create shortcuts to folders
prgramatically..

01. Add a reference to WSH Library (COM References Tab > Scripting Host
Object Model)

the following code creates a shortcut on desktop with various options given...

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


Sudhakar Sadasivuni
http://weblogs.asp.net/ssadasivuni
MyUG : http://www.mugh.net

dev guy

unread,
Dec 9, 2004, 1:56:53 AM12/9/04
to
Hi

I did follw the instructions... though it works only for Files. And not
FOLDERs.

-- regards

"Sudhakar Sadasivuni[mvp]" <SudhakarSa...@discussions.microsoft.com>
wrote in message news:0A80317B-342A-449C...@microsoft.com...

0 new messages