Tech Off Thread

14 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

How do you create file shortcuts in Visual Basic?

Back to Forum: Tech Off
  • User profile image
    Khamul

    I have searched and found only C# guides, which, when converted, have proven useless. How do you create a file shortcut from Visual Basic.Net (2.0).

  • User profile image
    Sven Groot

    Add a reference to the COM library "Windows Script Host Object Model" to your project, then use the following code:

    Imports IWshRuntimeLibrary

    ...

    Dim shell As WshShell = New WshShellClass
    Dim shortcut As WshShortcut = shell.CreateShortcut("notepad shortcut.lnk")
    shortcut.TargetPath = "notepad.exe"
    shortcut.IconLocation = "notepad.exe,0"
    shortcut.Description = "Launches Notepad"
    shortcut.Save()


    That's it.

  • User profile image
    El Bruno

    Sven is right ...

    but I don't like the use of com object in .Net ... so I propose the creation of a new class library to do this, for the .Net 2.0 Framework ...


    http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=615bf0fc-7575-45ca-96e5-d8346e897579


    It's still under review ...

    Bye from Spain

  • User profile image
    dotnetjunkie

    Ugh, that's ugly, let's all vote on that suggestion!

    Something as easy as creating a shortcut should definitely be possible from the managed framework.

  • User profile image
    AndyC

    I don't really see a legitimate reason for doing so. The only time you'd normally want to create shortcuts is during installation and Windows Installer can already do that for you.

    Am I missing something?

  • User profile image
    Khamul

    Thanks guys.

    "I don't really see a legitimate reason for doing so."

    Is there an illegitimate reason for creating shortcuts?

  • User profile image
    AndyC

    Khamul wrote:

    Is there an illegitimate reason for creating shortcuts?


    Yes.

    Usually that the application vendor thinks they're doing the user a favour by polluting his/her desktop with unnecessary icons.

  • User profile image
    W3bbo

    AndyC wrote:
    Khamul wrote:
    Is there an illegitimate reason for creating shortcuts?


    Yes.

    Usually that the application vendor thinks they're doing the user a favour by polluting his/her desktop with unnecessary icons.


    That's why they have a checkbox:

    "Do you want to create a shortcut to %programname% on your desktop?"

  • User profile image
    AndyC

    W3bbo wrote:


    That's why they have a checkbox:

    "Do you want to create a shortcut to %programname% on your desktop?"


    Yes, good installers do, hence my pointing out that you can already do this with Windows Installer, so .Net code to do it is unlikely to be necessary.

    When you start wanting to do it programmatically from within a .NET Application you should be asking yourself the question "What if everyone did this?" because you're likely to be going down a route that you shouldn't.

    I (and many other admins) have been in many a situation where the choice between two very similar applications has come down to the fact that one of them does something stupid like creating shortcuts at runtime that I don't want. Making applications that don't behave themselves can cost you money.
     

  • User profile image
    W3bbo

    Wait...

    What if he was writing a program to manage shortcuts? Wink

  • User profile image
    AndyC

    I didn't say there weren't any reasons. Smiley

    I'm just questioning how it adds value to the framework. It's seems to be something that should only be done in extremely rare circumstances and, as such, I'd rather developers were disuaded from doing it.

    If you make it too easy to do, everyone will do it.

  • User profile image
    leighsword
  • User profile image
    W3bbo

    AndyC wrote:
    If you make it too easy to do, everyone will do it.


    Yep, that's why:

    a) Everyone uses tables for page layout
    b) Almost every HTML form on the planet has <input type="reset" /> with no undo button
    c) Everyone uses Windows Wink

  • User profile image
    Khamul

    As a matter of fact, the program does manage shortcuts in a mock representation of Vista's Virtual Folders (except not as good, because they can't be updated automattically and VB .Net 2.0 programs are HELL to run in the background (this is bound to bring down a heap of posts on memory management, isn't it)).

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.