Results 1 to 3 of 3

Thread: Create a shortcut using IWshRuntimeLibrary

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Create a shortcut using IWshRuntimeLibrary

    Hello, if you were wondering how to create a shortcut for your application, here's a way to do it, using the IWshRuntimeLibrary .

    First off, you need to add a reference to your application. You do this by right-clicking on the References menu item in the Solution Explorer. Select the Add Reference menu. From the Add Reference dialog, click the .COM tab and select the 'Windows Scripting Host Object Model' and click the 'Add' button.

    After you have done that, just paste this code into your project, and voilá, you're done! .

    vb.net Code:
    1. Imports IWshRuntimeLibrary
    2.  
    3.     Public Sub CreateShortCutOnDesktop()
    4.         Try
    5.             Dim ShortCut As IWshRuntimeLibrary.IWshShortcut
    6.  
    7.             'Shortcuts have a .lnk extension...
    8.             ShortCut = CType(WshShell.CreateShortcut(My.Computer.FileSystem.SpecialDirectories.Desktop & _
    9.               "\MyAppName.lnk"),  _
    10.                 IWshRuntimeLibrary.IWshShortcut)
    11.  
    12.             'Let's set the shortcut properties...
    13.             With ShortCut
    14.                 .TargetPath = _
    15.                    System.Reflection.Assembly.GetExecutingAssembly.Location()
    16.                 .WindowStyle = 1
    17.                 .Description = "A description for the shortcut.."
    18.                 .WorkingDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
    19.                 'This next line gets the first icon from the executing application..
    20.                 .IconLocation = _
    21.                   System.Reflection.Assembly.GetExecutingAssembly.Location() & _
    22.                   ", 0"
    23.                 .Save() 'And save the shortcut...
    24.             End With
    25.         Catch ex As System.Exception
    26.             'Do something
    27.         End Try
    28.     End Sub

    I hope you have found this easy and helpful.

    Cheers .
    Last edited by tassa; Oct 7th, 2009 at 09:42 PM.
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width