Creating Shortcuts For Applications/Files

Hello Again Everyone,

Once again I am asking for help from all you wonderful people here in the Visual Basic Forum.

I have developed a nice small application that runs great and does everything I want it to do.  I would like to include code in the 'Installation' application that I created to create a normal application shortcut to place in the Startup Menu that points to the application I am installing and possibly to place a shortcut on the desktop during the 'Installation' execution if the user desires.

I have looked on the forums and only find references to code samples in "C" and not VB.  I know there must be a way to do it in VB.  Please let me know your replies and please include a code sample if possible.

Many thanks to all for your time and efforts in helping those of us interested in expanding our programming abilities.

Happy Holidays To All,
Doc


Answer this question

Creating Shortcuts For Applications/Files

  • Nathan Franklin

  • RobinChatterjee

    Thank you for your reply to my cry for help.  I do know about the "ClickOnce" and it seems that either I do not have enough knowledge to configure it properly or the "Visual Basic Express" version does not allow for many of the options (like the 'Editors' under the 'View' menu option [They don't seem to be there like the help files indicate]).  I have used the ClickOnce option to 'Publish' but where my application is loaded to (and run from) and the path structure and options to include extra configuration files used (and can be created by the end user when using the application) to be packaged in the 'Setup.exe' file does not seem possible with my limited knowledge I guess.  I am writing a separate 'Install.exe" application to allow the end user to place the main application file and it's 'extras' in a created default folder location (specified in the Install.exe app) in 'Program Files' or browse and select their own preference to where the main application is loaded and run from.  In addition I would like to create a shortcut file for the main application and add that shorcut to the menu structure and to the Desktop if the end user wants it there (checkbox control).  Everything is done for the 'Install.exe' app and it works great but I would like to know the way to create a program/file shortcut using Visual Basic Code

    In reality what I really need to know is how to create a program/file shortcut file by writing VB code.

    If I am completely off base and totally ignorant about the 'publish' process within the structure of Visual Basic Express then by all means let me know.  If this is the case would you be kind enough to point me in a direction to where I can learn about the 'publish' process so that it will do what I have indicated above

    This main application is just a simple program to manage file/folder structures for another large commerical program.  It only has the one main application (.exe) file and several support text files (for option and configuration defaults) that would be nice to have included with the main program so the end user does not have to start from scratch.

    I am sorry to take up so much of your time but help would be appreciated.  This VB Express is a fantastic programming tool, and I know what I am asking for must be able to be accomplished using VB Express code.

    Awaiting your reply,  Happy Holidays,

    Doc

  • cgpl

    Hi Steve,

    Just A short update.  First off, everything came out great after some additional learning on my part.  I know what follows will seem so simple to you but it took a little bit for me and a little research that I thought I might pass on to you to add to your teaching tools for those of us who haven't even read "Visual Basic Express 2005 For Dummies!" yet.

    I was a bit of a rough day today for me but I did get up late this afternoon and type in the code from the example that you referenced.  With the very first line I typed in there was a problem.  The line was "Imports IWshRunTimeLibrary" in the 'General Area' of the module page (before the module declaration).  VB said that it did not know what I was talking about.  I knew the code had to be good and there was something I was not doing.  This was the same line that caused problems on the 'C' example that I spoke of earlier that I attempted to convert to VB.

    Well, I decided to search the Microsoft Web site and low and behold I found a reference that really spelled it out for me.  It was a simple matter of adding a reference to the 'Windows Scripting Host Object Model (wshom.ocx)' in the project.  when I added it using the option in Solution Explorer the 'Green Underline' went away and everything went smoothly from that point on.  I put in the code that you referenced exactly and ran it and it worked great.  I have now modified the code so that it will put a shortcut anywhere I tell it to, yes even the desktop.

    I learned so much from this example you pointed me to and from the reference article I found as well, which has a downloadable file with all the code and examples.  The reference article I found was located at the following address:

    http://msdn.microsoft.com/library/en-us/dnadvnet/html/vbnet07232002.asp

    Title: Drives and Directories and Files! Oh, My!

    It is a wonderful article, filled with lots of great information and the download as well.  It is perfect for us "Real Dummies" trying to be VB programmers and working with the system file structure.

    As I said before, this additional article might also be a good reference for you to make to others that ask for help and are on the lower rungs of the VB learning ladder.

    I do hope all is well for you and that your holiday season will be wonderful, happy and safe.  All your help, support, encouragement, and wise words have been a wonderful holiday gift for me and I have even grown a bit more because of them.  I do hope that you continue to help others as you have me and in the far future, when I know a great deal more I will also want to follow in your compassionate footsteps to give my time, knowledge, and wisdom to others who need it as well.

    It has been a wonderful experience learning from you and I hope that we communicate again.

    Until that time, Happy Holidays,

    Your Humble Student,
    Doc


  • Kiwi86

    Great Thread Doc,

    I am also new but Old Programmer(wrote my first one on a Commodore VIC 20 back in 1981).... not over the hill yet ...
    I learned a lot from your comments and the replies you received... congrats to MS on finally opening up the cauldron...

    Good Luck

     



  • Robert Wishlaw

    Hi Doc,

    One of the limitations of ClickOnce is that you cannot control the installation location. If you stop and think about it, it really isn't such a bad thing for most applications. Does the user really need to know (or care) where the app is installed As long as your app knows where it's related files are, does it really matter where it's installed For the majority of applications, the answer to both of these questions is no. ClickOnce makes things easier by hiding unnecessary complexity from both the developer and the end user.

    Your post does bring back memories - I too am over 50, but I took up programming later in life. I remember trying to learn to program against Windows 3.0 using Borland's Turbo Pascal, an object-oriented development language called Actor, and several other products, all without much success. Then in 1991 Visual Basic 1.0 came out and I took to it like a duck to water - and the rest is history.

    I wish you the best of luck as you "re-learn" programming with Visual Basic Express!

    - Steve Hoag

  • Sunny H

    Hi Doc -

    If you publish your application using ClickOnce and choose the option to make the app available both online and offline (the default), a shortcut is automatically added to the Start menu. There is no option for adding a shortcut to the desktop, but the end user can easily accomplish this by dragging from the Start menu to the desktop.

    Hope this helps,
    Steve Hoag
    Visual Basic Express

  • Anderson505

    I think you are confusing two different methods of deploying an application. The docs the refer to Editors under the View menu are talking about Setup and Deployment projects used to create Windows Installer-based setups. Setup and Deployment projects are only available in the full versions (Standard and above) of Visual Studio. Since this is an an Express forum, I am assuming that you do not have access to Setup and Deployment projects, so I am curious what you are using to create your "Install.exe" app.

    ClickOnce deployment is a new technology available in all versions including Express - in fact, it is the only deployment technology included in the Express edition. It couldn't be simpler - just click Publish and step through a simple wizard, and everything is taken care of for you. Any additional files in your project that are marked as Content (the default) will be installed along with the application, and a shortcut is automatically added to the Start menu (and to Add/Remove Programs in the Control Panel).

    It sounds like this would be ideal for your application - the only thing that ClickOnce won't handle is installing a shortcut on the Desktop.

    Take a look at the ClickOnce documentation starting with "How to: Publish a ClickOnce Application": http://msdn2.microsoft.com/en-us/library/31kztyey.aspx

    - Steve

  • brohar

    I figured out how to do this without manually editing the .msi

    This same question was asked in several different threads so I put the answer in a central place here:

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1221084&SiteID=1&mode=1

    Jacob Wagner
    Sr. IT Technician
    American River College
    wagnerjp AT arc DOT losrios DOT edu


  • kharera

    One thing that I thought of as I was reading this thread, was that you might try adding some specific deployment code (like adding desktop shortcuts) to the initialization of your application.  There is a way to determine if the current execution of your app is the first execution since it was deployed.  Let me know if you want me to look up where I found this.

       Ed Tenholder

     

     

     Doc Adams wrote:

    Hi Steve,

    Just A short update.  First off, everything came out great after some additional learning on my part.  I know what follows will seem so simple to you but it took a little bit for me and a little research that I thought I might pass on to you to add to your teaching tools for those of us who haven't even read "Visual Basic Express 2005 For Dummies!" yet.

    I was a bit of a rough day today for me but I did get up late this afternoon and type in the code from the example that you referenced.  With the very first line I typed in there was a problem.  The line was "Imports IWshRunTimeLibrary" in the 'General Area' of the module page (before the module declaration).  VB said that it did not know what I was talking about.  I knew the code had to be good and there was something I was not doing.  This was the same line that caused problems on the 'C' example that I spoke of earlier that I attempted to convert to VB.

    Well, I decided to search the Microsoft Web site and low and behold I found a reference that really spelled it out for me.  It was a simple matter of adding a reference to the 'Windows Scripting Host Object Model (wshom.ocx)' in the project.  when I added it using the option in Solution Explorer the 'Green Underline' went away and everything went smoothly from that point on.  I put in the code that you referenced exactly and ran it and it worked great.  I have now modified the code so that it will put a shortcut anywhere I tell it to, yes even the desktop.

    I learned so much from this example you pointed me to and from the reference article I found as well, which has a downloadable file with all the code and examples.  The reference article I found was located at the following address:

    http://msdn.microsoft.com/library/en-us/dnadvnet/html/vbnet07232002.asp

    Title: Drives and Directories and Files! Oh, My!

    It is a wonderful article, filled with lots of great information and the download as well.  It is perfect for us "Real Dummies" trying to be VB programmers and working with the system file structure.

    As I said before, this additional article might also be a good reference for you to make to others that ask for help and are on the lower rungs of the VB learning ladder.

    I do hope all is well for you and that your holiday season will be wonderful, happy and safe.  All your help, support, encouragement, and wise words have been a wonderful holiday gift for me and I have even grown a bit more because of them.  I do hope that you continue to help others as you have me and in the far future, when I know a great deal more I will also want to follow in your compassionate footsteps to give my time, knowledge, and wisdom to others who need it as well.

    It has been a wonderful experience learning from you and I hope that we communicate again.

    Until that time, Happy Holidays,

    Your Humble Student,
    Doc


  • Alexandre M

    Hi Doc,

    Creating your own installation program is an interesting approach, and apparently it is working for you, however I must caution that this approach has a potential pitfall. Your application undoubtedly requires the .Net runtime and possibly other prerequisites - if you try to install onto a computer that doesn't have the prerequisites, the app will install but it won't run. ClickOnce takes care of this for you by detecting prerequisites and installing them if necessary.

    If you can live with the limitations, I did find the following thread that shows how to create a desktop shortcut using a "roll your own" deployment approach:
    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=67842&SiteID=1

    Note that this code is unsupported and will not work with ClickOnce.

    Personally I would take the easier route and use ClickOnce at the expense of requiring the users to drag and drop the shortcut from the Start menu.

    Best wishes,
    Steve

  • How do I

    You're a brave man to use the windows scripting host from an application !

    The ClickOnce deployment (as used by the express editions) is fine for only the most absolute basic of installs. I'd recommend either getting hold of VS2005 Professional and trying out the more configurable deployment tools, or getting a completely separate installer application.

    I prefer the latter (at least it gives a change of pace from the Microsoft tools!) and I currently use the Nullsoft (NSIS) system: can be configured to create shortcuts, check registry entries (Detect if the .NET runtimes are installed!),, the list goes on. They have a great forum/community and a dedicated team of developers, as well as regular contributors. It's a bit clunky to configure (it's script based), but works extremely well. There are a couple of others out there - some free and some not. Give them a try, when you have time

    NSIS Can be found here, for your interest: http://nsis.sourceforge.net/Main_Page

    SJW



  • Angelito

    Steve,

     < xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    Thank you for being so patient and understanding.  I know there is so much to learn with even this "Express" version of the environment.  Your latest reply answered my question perfectly and completely.  Thank you so much.


    I will heed your experienced advice and guiding words.  I am going to work more with the ClickOnce Option to see if I can have it work for my needs.  It truly is a wonderful option.  I am including the .Net Frame package as well as the Windows Installer 3.1 on the CD's that I burn so that the end user can install them if they do not already have them.  However, the people who will most likely get my application will already have the latest and greatest of these versions running due to the fact that the "commercial application" that I spoke of requires that these packages be there to run it.  In addition, no one would want to run my application if they did not already have the "commercial application" in place.  My application would be totally useless to them.  This is so important that I have written the application to ensure that the "commercial application" is in fact installed and if not exits promptly without doing anything. In addition, it will only perform its functions if that "commercial application's" save files exist in the folder that is being accessed.


    All this said, I am printing out a copy of the thread you referenced for me so that I may study the code listed.  It looks like if nothing else it will point me in the right direction.  I will close now and would like once more to say thank you for all your efforts, time, and patience in helping me to grow more into this wonderful programming environment.  I have been mostly an advanced “C” programmer for many years but have not done much since the onset of the windowing environment.  When I stopped actively programming there was only Windows 3.0 and 3.1 was just being introduced, and the company I was working for had Borland’s ‘C’ Environment which had the first GUI for designing windows apps.  I was called OWL (Object Windowing Language).  When you just made a simple window with a string text of “Hello World” it generated over 35 printed pages (dot-matrix printing) of source code.  You then had to compile everything first before you could even find out if it worked or had bugs.  If there were bugs… well you started all over again.  Most of  my skills have come from what we used to call the “Command Line Interpreter” environment (MS DOS 6.2).  Do you remember any of these   By now you will have guessed that I am, let’s say, over 50 years old and I have turned back to programming because of the severe limitations that my health condition now places on me.  I just thought you might find this interesting.


    One last question.  Do you know if it is possible to configure the ClickOnce to install my application in a place a little more common or even to the root directory of the system drive


    I will always remember your kindness and guidance.  Perhaps one day this student can help and repay the master.

    Until then, may love, compassion, and true happiness always be with you,

     

    Your new acquaintance,

     

    Doc


  • Alex Simkin

    Hello Steve,

    First of all I would like to thank you so very much for staying with me on these questions I have.  I am sorry for my limited knowledge and understanding of these seemingly basic issues of Visual Basic.  Your efforts to help me increase my knowledge and get resolutions to my problems are greatly appreciated.

    The first thing I have learned from your most recient reply to my cry for help is that I can not deploy using Windows Installer and that because of the version I have (Express) I am limited to use the ClickOnce Publish option.  This is what I figured was the case when the editors that the help information referred to in the 'View' menu option were not there no matter what section of my project I selected.  I am please to learn that all it seems I need to do is to pull the extra folder of configuration files used by my project into the project lay out and ensure that the folder is assigned to be "Content" and it will be included in the installation load.

    The problem I have is that the 'Setup.exe' that is created installs the application and related files to a folder in the "Documents & Settings\Doc" user folder (that's me) in a nested folder of "Apps" and even deeper nested in a numbered folder.  What I fear is that when I give this application to others who do have me as a user on their system or network it will not work, or create me as a user which I do not want.  In addition, the 'Setup.exe' places a menu option in the startup using the "Company Name" as the folder that holds the application.  To get the folder on the startup menu to be what I want it named to requires that I change the "Company Name" under the projects preferences.  That works OK.  But I can not seem to find how to get the created 'Setup.exe' to install the application in a more common folder (like "\Program Files" or "Program Files\Common" or even it's own folder on the root of the main drive (Like Adobe products do).

    That brings me to your question about my "Install.exe" file.  All I have done is to write a separate project application with controls that have defaults and allow the installing user to select, if they want to, where the application will load to.  It also allows for the inclusion of the 'extras' that I would like to provide for use by the application being installed.  I know that it is probably not the correct way to do it but it seems to work just fine.  I then package up the entire application to be installed along with the 'Install.exe' and burn it to a CD with a autorun script pointing to the "Install.exe" file and it works great.  However, creating a shortcut file seems to be the stumbling point.  I also am aware that I will not have the 'remove' option that the ClickOnce provides but this is such a simple application that it really is not needed.

    I still would like to know if it is possible to write VB code that would create a shortcut file.  As I stated earlier, I did find the same question asked in the .NET forum and the answer was clear and concise but the code was in "C" not VB.  I tried to convert the "C" code to VB and was mostly successful except for a few references which I do not know how to make.  This is the real nature of my original question, which is "What is the Visual Basic Code that would create a shortcut file "

    I do hope that I do not come across as not being appreciative for all your patience and help.  I am ever so greatful.  Once again, I appologize for by severe lack of knowledge about this programming environment.  I am in a financal position of not being able to afford the "bigger & better" version of this environment and I was hoping that I could write this simple application that is desparatly needed by my professional community and get some revenue so that I might be able to afford the "bigger & better" version.

    Please hang in there with me and reply with any thoughts that you might feel are constructive.  Thank you for all your time, efforts and patience with me so far.

    Happy Holidays,
    Doc


  • Creating Shortcuts For Applications/Files