.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Shortcut Icon through code in .net

Posted By:Mahesh       Posted Date: March 29, 2012    Points: 200    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

Ths article will show how to add an short cut icon through code in vb.net application.

Hi All,

   There is some situations when we want to create an shortcut icon in start menu or on desktop using .net code other than installer.

   Following code uses Wscript.Shell for achiving this as,

Shell object is cretaed as, 

Dim wsh As Object = CreateObject("WScript.Shell")

wsh = CreateObject("WScript.Shell")

Dim MyShortcut As Object

Dim sStartMenuPath As String

'Path is given where we wants to create shortcut

'Read desktop path using WshSpecialFolders object

'DesktopPath = wsh.SpecialFolders("Desktop")

sStartMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu)

If Not Directory.Exists(Path.Combine(sStartMenuPath, "Application Name")) Then

Directory.CreateDirectory(Path.Combine(sStartMenuPath, "Application Name"))

End If

' Create a shortcut object on the desktop

MyShortcut = wsh.CreateShortcut(Path.Combine(sStartMenuPath, "Application Name") & "\ApplicationIconName.lnk")

' Set shortcut object properties and save it

MyShortcut.TargetPath = wsh.ExpandEnvironmentStrings("C:\Program Files\Application Name\Application.exe")

MyShortcut.WorkingDirectory = wsh.ExpandEnvironmentStrings("C:\Program Files\Application Name\")

MyShortcut.WindowStyle = 4

'Use this next line to assign a icon other then the default icon for the exe

'MyShortcut.IconLocation = WSHShell.ExpandEnvironmentStrings("path to a file with an embeded icon", icon index number)

'Save the shortcut


In this way we can create shortcut icon using .net code other than installer.




Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend