Desktop Shortcut

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

Desktop Shortcut
CodenStuff
Hello,

This code will add a shortcut for your application on the users desktop:

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 DesktopShortcut As WshShellClass = New WshShellClass
        Dim MyShortcut As IWshRuntimeLibrary.IWshShortcut
        Dim MyIconFile = "C:\NameofIconToUseOnShortcut.ico"
        Dim Desktop As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
        MyShortcut = CType(DesktopShortcut.CreateShortcut(Desktop & "\" & Application.ProductName & ".lnk"), IWshRuntimeLibrary.IWshShortcut)
        MyShortcut.TargetPath = Application.ExecutablePath
        MyShortcut.IconLocation = MyIconFile
        MyShortcut.Save()
Change "C:\NameofIconToUseOnShortcut.ico" to the filename and location of an icon file you wish to display as your shortcut.

Thats all you have to do, no need to change anymore code 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: Desktop Shortcut
Scottie1972
This is great..I was wondering if there was a way to do this or not.
Image
User avatar
Miutubevids
VIP-Member
VIP-Member
Posts: 293
Joined: Mon Nov 23, 2009 11:39 am

Re: Desktop Shortcut
Miutubevids
CnS goes b1g in Shortcuts
Don't BS the BSer

RePlay V1.0 - Record your Mouse Clicks, Mouse Movments and Keystrokes
AutoClicker v1.0
SnowScreen
Reaction Timer Game V1.0
User avatar
RonaldHarvey
Top Poster
Top Poster
Posts: 113
Joined: Tue Apr 05, 2011 2:32 pm

Re: Desktop Shortcut
RonaldHarvey
codenstuff, thanks I tried it and it works. cooll;
4 posts Page 1 of 1
Return to “Quick Snips”