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

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to create shortcut icon in vb.net

Posted By: Mahesh     Posted Date: June 21, 2012    Points:5   Category :VB.Net
How to create shortcut icon for an exe through code in vb.net

Author: Mahesh             
Posted Date: June 21, 2012     Points: 20   

oWScriptShell = CreateObject("WScript.Shell")

'Read desktop path using WshSpecialFolders object
sStartMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu)

If Not String.IsNullOrEmpty(oTaskStruct.StartMenuDirectoryPath) Then
sFolders = MenuDirectoryPath.Split("\")
sFolderPath = sStartMenuPath
For Each sFolder As String In sFolders
sFolderPath = Path.Combine(sFolderPath, sFolder)

If Not Directory.Exists(sFolderPath) Then
End If
End If

' Create a shortcut object on the desktop
oShortcut = oWScriptShell.CreateShortcut(Path.Combine(Path.Combine(sStartMenuPath, MenuDirectoryPath), LinkName & ".lnk"))

' Set shortcut object properties and save it
oShortcut.TargetPath = oWScriptShell.ExpandEnvironmentStrings(Path.Combine(ShortcutIconExePath, ShortcutIconExeName))

oShortcut.WorkingDirectory = oWScriptShell.ExpandEnvironmentStrings(ShortcutIconExePath)
oShortcut.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

Author: Eone James             
Posted Date: June 14, 2013     Points: 20   

You can also use following code.

Imports IWshRuntimeLibrary


Dim shell As WshShell = New WshShellClass
' Determines the Desktop folder for current user
Dim Desktop As String = Environment.GetFolderPath(SpecialFolder.DesktopDirectory)
Dim shortcut As WshShortcut = shell.CreateShortcut(Desktop & "/ShorcutName.lnk")
shortcut.TargetPath = "The exe to create shortcut for"
shortcut.Description = "Description (optional)"

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

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