Results 1 to 3 of 3

Thread: Make shortcut [RESOLVED]

  1. #1

    Thread Starter
    Lively Member freightliner's Avatar
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    123

    Make shortcut [RESOLVED]

    How can you create a shortcut on the desktop. i have code to make shortcut(i think it works) but how can i obtain the desktop path?
    Last edited by freightliner; Oct 19th, 2004 at 03:17 AM.
    very handy: [vbcode][/vbcode]
    VB.NET - VB6 - VBA - ASP - RPG(AS/400) - C++ - java - SQL

    look in the help, many probs can be solved that way.
    I know, i'm to lazy too.

    PLEASE PUT RESOLVED IF RESOLVED!!

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667
    Hi there i have come across two methods in travells with VB.
    Please note niether of these methods were produced by me.

    1)
    Make P&D Wizard create Desktop shortcuts

    Author:
    W. Baldwin




    Version Compatibility:
    Visual Basic 5 Visual Basic 6


    More information: This article shows that, by adding just 4 lines of code, the Packaging & Deployment Wizard and Setup1.vbp can be easily modified to create Desktop shortcuts, as well as Start Menu shortcuts.

    This code has been viewed 1509 times.

    Make P&D Wizard/Setup1.exe create Desktop shortcuts W. Baldwin

    These instructions are for VB 6.0, but, with some modification, will probably also work for earlier versions.

    The Packaging and Deployment Wizard (P&D Wizard) is a pretty good tool for creating installation packages. Along with the other things it does, it will create shortcuts in the Start Menu. Unfortunately, it won't create Desktop shortcuts; however, with just a few lines of code (added to Setup1.vbp), it can be *easily* modified to create them.

    Before attempting this modification, make sure you save the Setup1.vbp files somewhere for backup purposes. Also, read the sections on the MSDN CD, concerning the relationship between the P&D Wizard and Setup1.vbp, and sections concerning how to modify Setup1.vbp. First, check the index tab for 'Setup1.vbp', and read that, which tells you the location of the project files. Then, under the Contents tab, VB, 'Getting Started with VB', 'Find it Fast', read the sections dealing with 'Distributing your applications'.

    At the end of this article there are listed some more articles from Microsoft's Knowledge Base, and www.allapi.net, which are good supplemental reading.

    Although there are a number of ways to create a Desktop shortcut outside of Setup1.exe, modifying Setup1.exe to create them, instead, has a number of benefits, including a built-in install recovery routine in case of failure, and logging the shortcut creation in St6Unst.log. The latter is important, so that, if the user subsequently uninstalls your application, the uninstall routine will also cleanly remove the Desktop shortcut(s).

    The procedure is as follows:

    1) In frmSetup1's Form_Load event, look for the line:

    Case UCase$(gsSTARTMENUKEY), UCase$(gsPROGMENUKEY)

    and modify it to say:

    Case UCase$(gsSTARTMENUKEY), UCase$(gsPROGMENUKEY), "DESKTOP"

    What these lines do, is skip creating a Start Menu Group for the groups 'Start Menu' and 'Programs', because those Groups already exist. We are then adding a *new* keyword "DESKTOP" which tells it to also skip creating a 'DeskTop' group, because we don't want to create that group in the Start Menu, but only add a Desktop shortcut, instead.

    2) Then, in basSetup1's 'CreateIcons' Sub, look for the lines:

    Loop

    CreateShellLink strProgramPath, strGroup, strProgramArgs, strProgramIconTitle, fPrivate, sParent

    and, insert 3 new lines so that it now looks like:

    Loop

    If UCase(strGroup) = "DESKTOP" Then
    strGroup = "..\..\Desktop"
    End If

    CreateShellLink strProgramPath, strGroup, strProgramArgs, strProgramIconTitle, fPrivate, sParent

    Important note: By modifying Setup1.exe this way, Setup1 will now treat the group 'Desktop' as a special keyword and always create the shortcut on the Desktop, rather than as another group in the Start Menu.

    3) Now, you're done with Setup1.vbp, and you can compile it. On my system, the .exe is in the PDWizard folder.

    Now that you've recompiled Setup1.exe, when you use the P&D Wizard, it should now package the new version of Setup1.exe with your install package.

    To make this work, you then need to modify the Setup.lst that was created when you used the P&D Wizard. What you will do is add a new IconGroup, named DeskTop, with one or more icons that you want to be created on the Desktop.

    Look for the [IconGroups] section in Setup.lst. It should look something like this, if you have told P&D Wizard to create Start Menu shortcuts:

    [IconGroups]
    Group0=Your Application
    PrivateGroup0=-1
    Parent0=$(Programs)
    If the [IconGroups] section doesn't already exist, just add it.

    At the bottom of that section, add a new IconGroup for your Desktop shortcut(s) like:

    Group1=DeskTop
    PrivateGroup1=-1
    Parent1=$(Programs)
    The '1' subscript on the keyword for each line has to be incremented by 1 for each IconGroup you already have, so if Setup.lst already has a Group1, you'd use Group2, PrivateGroup2, Parent2, or Group3, PrivateGroup3, Parent3, etc.

    Next, somewhere after the IconGroups section, add a new [DeskTop] section:

    [DeskTop]
    Icon1="Your Application.exe"
    Title1=Your Application
    StartIn1=$(AppPath)
    This is assuming that the target of your Desktop shortcut is in the $(AppPath) folder. $(AppPath) is a macro that tells Setup1.exe that the target program is in your main application folder. There are other macros you can use, instead, that are documented on the MSDN CD and the Knowledge base.

    If you want more Desktop shortcuts, just add them under the first one, but use Icon2, Title2, StartIn2, Icon3, Title3, StartIn3, etc.

    Now you're done. When you or the user runs Setup1.exe, it should now create a Desktop shortcut.

    Check these Microsoft Knowledge Base articles for further information:

    Description of Setup.lst Sections (Q189743)
    Run Setup1.vbp in the Design Environment (Q189738)
    Package and Deployment Wizard Installation Macros (Q189739)
    Create Shortcuts (Shell Links) within Windows (Q155303)

    Note: The last one, above, covers how to create shortcuts in VB 5.0, using the fCreateShellLink API. That example doesn't work correctly in 6.0, but you can find the updated example which *does* work in 6.0 at www.allapi.net. At that website, click on 'API List', then search for fCreateShellLink, then click the 'CreateShellLink V6' example.
    2)

    Philip Pursglove ([email protected])
    SHORTCUTS

    Before the Scripting Host came along, the adage that ‘shortcuts make long delays’ was true for VB developers. If you wanted to programmatically create a shortcut, you needed to create a .lnk file, find the location of a folder such as the Desktop or Start Menu, and then copy your .lnk file into that folder. There are articles on MSDN that describe how to do this using API calls to get the path to these kinds of folders; we’ve already seen how easy it is to use the Shell to access this kind of information.

    Shortcuts come in two flavours: Shortcut and URLShortcut. A Shortcut is a normal shortcut that you find on a desktop, while as the name suggests, a URLShortcut is a desktop shortcut which points to an Internet URL. URLShortcuts have only two properties, while Shortcuts have seven. Shortcuts allow you to create shortcut files in any folder, although you’ll get the most benefit by either putting them on the desktop or in the Start menu.

    Shortcuts can only be created by the CreateShortcut method of the Shell object. This method takes one parameter, which is the location the shortcut should be created in. You can also use the method to get a reference to an existing shortcut if you want to amend it. However, this parameter also determines what kind of shortcut is created. If the path to the shortcut ends in ‘.url’, then a URLShortcut is created; if the path ends in ‘.lnk’, then a Shortcut is created.

    Both kinds of Shortcut have TargetPath and FullName properties. The FullName property gives the full path to the shortcut file. For a URLShortcut, the TargetPath property is the URL that the shortcut points to; for a Shortcut, the TargetPath is the path to the executable file.

    Dim VBD As IWshRuntimeLibrary.IWshURLShortcut_Class
    Dim VBExe As IWshRuntimeLibrary.IwshShortcut_Class
    Dim VBPath As String

    Set VBD = MyShell.CreateShortcut _
    (MyShell.SpecialFolders("AllUsersDesktop") & _
    "VBD.url")
    VBD.TargetPath = "www.pinnaclepublishing.com/vbd"
    VBD.Save

    VBPath = _
    "C:\Program Files\Microsoft Visual Studio\VB98\VB6.EXE"

    Set VBExe = MyShell.CreateShortcut _
    (MyShell.SpecialFolders("AllUsersStartMenu") _
    & "VB6.lnk")
    VBExe.TargetPath = VBPath
    VBExe.Save
    Shortcut objects have additional properties, which allow you to set any of the properties you can access in the Properties dialog of a shortcut in Windows Explorer. The WorkingDirectory property is a string which must point to a valid folder accessible by the shortcut e.g. C:\TEMP. WindowStyle is an integer value which sets the style of the window which the referenced executable runs in. The Hotkey property allows you specify a key or combination of keys to use as a keyboard shortcut to trigger the shortcut. Hotkey is a string, which must be written in the format ‘modifier + keyname’, where modifier specifies keys such as ALT or Shift, and keyname is the actual key which can be either one of the alphanumeric keys or one of a number of special keys including Return and Escape e.g.

    VBExe.HotKey = "ALT + SHIFT + V"

    IconLocation allows you to select a specific icon for your shortcut; it takes a string parameter which is made up of a path, which is usually to the target executable but could be to another file like moricons.dll, followed by an index number, which is the index number of the icon inside the filename.

    VBExe.IconLocation = VBPath, 0

    Shortcuts only have one method: Save, which is the method by which a shortcut is saved to a file on a disk.
    hope this helps

    (Both these methods can be found in my VB.Classic help file, this can be download by following the link below)


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