Results 1 to 3 of 3

Thread: Create a shortcut using IWshRuntimeLibrary

  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

  2. #2
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,450

    Re: Create a shortcut using IWshRuntimeLibrary

    Quote Originally Posted by tassa View Post
    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.
    Thanks Tassa,

    I wish I'd found that two days ago! I did find something similar but they're description must've lacked something because it made no difference.


    Poppa.
    Along with the sunshine there has to be a little rain sometime.

  3. #3
    New Member
    Join Date
    Jan 2023
    Posts
    7

    Re: Create a shortcut using IWshRuntimeLibrary

    All,
    I am pretty new to VB and I am using VB 2010 Express. I copied the above code, adjusted the variables to point to the right files and locations. I have added the reference to WSH Object models and imports Iwshruntimelibrary. I now have a compile error on line 8 of the above code. Specifically, with WshShell.CreateShortcut. The error is "Reference to a non-shared member requires an object reference. What does this mean and what am i doing wrong?

    Thanks

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