Start Menu Shortcut

Use this board to post your code snippets - tips and tricks
5 posts Page 1 of 1
Contributors
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4392
Joined: Tue Aug 04, 2009 1:47 am

Start Menu Shortcut
CodenStuff
Hello,

This code will add a shortcut to your application onto the start menu:

Make a reference to the "Windows Script Host Object Model" COM library and then in your code add:
Code: Select all
Imports IWshRuntimeLibrary
Then when you want to create your shortcut:
Code: Select all
Dim MenuShortcut As WshShellClass = New WshShellClass
        Dim NewShortcut As IWshRuntimeLibrary.IWshShortcut
        Dim MyAppFolder = "NameOfFolder"
        Dim MyIconFile = "C:\NameofIconToUseOnShortcut.ico"
        Dim StartMenuFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Programs)
        My.Computer.FileSystem.CreateDirectory(StartMenuFolder & "\" & MyAppFolder & "\")
        NewShortcut = CType(MenuShortcut.CreateShortcut(StartMenuFolder & "\" & MyAppFolder & "\" & Application.ProductName & ".lnk"), IWshRuntimeLibrary.IWshShortcut)
        NewShortcut.TargetPath = Application.ExecutablePath
        NewShortcut.IconLocation = MyIconFile
        NewShortcut.Save()

Change "NameOfFolder" to a folder name to store your shortcut into.

Change "C:\NameofIconToUseOnShortcut.ico" to the filename and location of an icon file you wish to display as your shortcut.

Happy coding cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

Re: Start Menu Shortcut
Scottie1972
This is always nice to know...I will have to try this in one of my apps.
Image
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

Re: Start Menu Shortcut
hungryhounduk
Cheers Codenstuff
as all with your codes, nice and easily laid out and very Handy :)
Image
User avatar
Livengood
Serious Programmer
Serious Programmer
Posts: 445
Joined: Tue Feb 16, 2010 6:24 am

Re: Start Menu Shortcut
Livengood
Thank you :D
Image
User avatar
RonaldHarvey
Top Poster
Top Poster
Posts: 113
Joined: Tue Apr 05, 2011 2:32 pm

Re: Start Menu Shortcut
RonaldHarvey
Great Job CodenStuff I already tried your snippets for Desktop shortcut Icon and it works... wahooo;
5 posts Page 1 of 1
Return to “Quick Snips”