MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: No Installation Registration[Next]: Uninstall Fails (Don't Panic)
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->URL Shortcuts

URL Shortcuts

In theory shortcut creation is as simple as using the Shortcut command as is shown below, however even something that seems so simple can be complicated, to help you think about your requirements I have listed some of the issues:

  1. Is the default browser icon acceptable or do you wish to specify your own?

  2. Would the user wish to have multiple windows open to the same location (at times this will make sense)?

  3. On the first (or subsequent) invokation of the URL should it reuse any existing browser session (window)? This is the default IE behaviour, you could leave it up to the user to change the IE setting and possibly mention in a "read.me" file but will a less knowledgable user be annoyed with your product?

  4. If the user clicks on your shortcut a second time, should it reuse the window created by the first use or start a new window in any case?

  5. If the user clicks on your shortcut a second time, should it change focus to the window created by the first use if the URL of the window matches and if it doesn't start a new window?

Any "reuse" of a window could potentially cause the user to lose their place (and possibly form data), so some of the decisions above would be based on good working knowledge of the particular site and how the URL changes (or doesn't). There is no "one size fits all".

Simplest Possible - Use Shortcut Command

<$DirectoryTree Key="INSTALLDIR"    Dir="c:\Program Files\SomeDir" CHANGE="\">
<$Component "UrlShortcut" Create="Y" Directory_="INSTALLDIR" CU="Y">
   ;--- Create directory for shortcut ---
   <$DirectoryTree Key="INSTALLDIR_SC" Dir="[ProgramMenuFolder]\Shortcut Directory" MAKE="Y" REMOVE="Y">

   ;--- Add icon ---
   <$Icon Key="@Google" "test.ico">               ;;Key must end in ".exe" (WI feature)

   ;--- Create a shortcut ---
   #(
       <$Shortcut
                   Dir="INSTALLDIR_SC"
                Target="http://www.google.com/"
                 Title="DB$ - GOOGLE"
           Description="Go to google"
                  Icon="@Google"
             IconIndex="0"
       >
   #)
<$/Component>

Advantages with the above are:

Disadvantages with the above are:

Just Use a ".URL" file

A shortcut as created via a browser is basically just a simple text file with the extension ".url" (which is hidden by Explorer).

An example of a "google.url" (with alternative icon and hotkey) is:

[InternetShortcut]
URL=http://www.google.com/
Hotkey=1606
IconFile=C:\WINDOWS\system32\url.dll
IconIndex=2

To work out the correct text simply drag a URL from IE to the desktop, customise it then open in a text editor (ignore anything outside the "[InternetShortcut]" section and remove the "modified" keyword.

Rather than have a whole "bunch" of these shortcuts to have to maintain, one option is to create them as part of your script as demonstrated below:

#define HTTP_GOOGLE  http://www.google.com/
<$FileMake "<$MAKEMSI_OTHER_DIR>\Google.url">
    [InternetShortcut]
        URL=<$HTTP_GOOGLE>
<$/FileMake>

As the shortcut s basically an INI file the Ini and related command can also be used if you wish.

Advantages with the above are:

Disadvantages with the above are:

Use the start command

The following is another way to kick off a URL:

start "" "http://www.google.com"

Advantages with the above are:

Disadvantages with the above are:

Start URL via IEXPLORE.EXE

You can specifically use IE to kick off your shortcut and make use of its (unfortunately very basic) command line switches (such as "-new").

The program is not in the path however there is no need to search for it, simply use the "START" command to invoke it as follows:

start IEXPLORE.EXE -new "http://www.google.com"

Advantages with the above are:

Disadvantages with the above are:

Start URL via EXPLORER.EXE

The following is another way to kick off a URL:

explorer.exe "http://www.google.com"

Advantages with the above are:

Disadvantages with the above are:

Use IE COM Object

The following is another way to kick off a URL:

;--- Create a macro to create a script to kick off a URL --------------------
#(
    ;--- Define macro, validate parameters ----------------------------------
    #define CreateUrlScript
    {$!:ALIAS,URL,WIDTH,HEIGHT,ExistingTest}

    #define+ URLFILE_{$Alias} <$MAKEMSI_NONCA_SCRIPT_DIR>\{$Alias}.VBS
    <$FileMake "<$URLFILE_{$Alias}>">
        #(  '<?NewLine>'
            ;--- Initialization ---------------------------------------------
            option explicit
            <?SyntaxCheck>

            ;--- Create some Objects ----------------------------------------
            dim oShell        : set oShell       = WScript.CreateObject("WScript.Shell")
            dim oApplication  : Set oApplication = WScript.CreateObject("Shell.Application")

            ;--- Get URL and start it ---------------------------------------
            dim Url      : Url      = "{$Url}"
            dim IeWidth  : IeWidth  = {$Width=^0^}
            dim IeHeight : IeHeight = {$Height=^0^}
            StartIeSessionOrBringExistingIntoFocus()

            ;--- Finished ---------------------------------------------------
            set oShell       = Nothing
            set oApplication = Nothing
            wscript.quit 0

            <?NewLine>
            <?NewLine>
            '============================================================================
            sub StartSessionViaExplorer()
            ' This starts a "normal" explorer window OR if it is already open
            ' (at exact same URL) effectively brings it into focus.
            '============================================================================
                oShell.Run("%WinDir%\explorer.exe """ & URL & """")
            end sub

            <?NewLine>
            <?NewLine>
            '============================================================================
            sub StartIeSessionOrBringExistingIntoFocus()
            '============================================================================
                ;--- Is there already a session running? --------------------
                dim oWindow
                for each oWindow in oApplication.Windows
                    ;--- Check this session ---------------------------------
                    if  {$ExistingTest=^ucase(oWindow.LocationURL) = ucase(URL)^} then
                        ;--- Bring the window into focus --------------------
                        StartSessionViaExplorer()   ;;Anyone know better way?
                        exit sub
                    end if
                next

                ;--- Start NEW session --------------------------------------
                dim oIE : set oIE = CreateObject("InternetExplorer.Application")
                oIE.menubar     = 1
                oIE.toolbar     = 1
                oIE.statusbar   = 1
                oIE.fullscreen  = 0
                oIE.resizable   = 1
                oIE.visible     = 1
                'oIE.StatusText = ""
                if  IeWidth <> 0 then
                    ;--- Size and center window -----------------------------
                    dim ScreenWidth, ScreenHeight
                    dim x, y
                    with CreateObject("htmlfile").ParentWindow.Screen
                         ScreenWidth  = .AvailWidth
                         ScreenHeight = .AvailHeight
                    end With
                    x  = (ScreenWidth  - IeWidth)  \ 2 : if x < 0 then x = 0
                    y  = (ScreenHeight - IeHeight) \ 2 : if y < 0 then y = 0
                    oIE.width   = IeWidth
                    oIE.height  = IeHeight
                    oIE.left    = x
                    oIE.top     = y
                end if

                ;--- Open New IE session at the URL -------------------------
                oIE.navigate URL

                ;--- Finished -----------------------------------------------
                set oIE = Nothing
            end sub
        #)
   <$/FileMake>
#)

;--- Use the above macro, passing any required parameters -------------------
<$CreateUrlScript Alias="google" Url='http://www.google.com.au/'>

;--- Add the file generated above to a component and create a shortcut ------
<$Component "UrlShortcut" Create="Y" Directory_="INSTALLDIR">
   ;--- Create directory for shortcut ---
   <$DirectoryTree Key="INSTALLDIR_SC" Dir="[ProgramMenuFolder]\Shortcut Directory" MAKE="Y" REMOVE="Y">

   ;--- Add the script generated above, its the keypath ---------------------
   <$File Source="<$URLFILE_GOOGLE>" KeyPath="Y">

   ;--- Add icon ------------------------------------------------------------
   <$Icon Key="@Google" "test.ico">               ;;Key must end in ".exe" (WI feature)

   ;--- Create a shortcut ---------------------------------------------------
   #(
       <$Shortcut
                   Dir="INSTALLDIR_SC"
                Feature="\"                 ;;Targe = the component keypath
                 Title="GOOGLE Search"
           Description="Go to google"
                  Icon="@Google"
             IconIndex="0"
       >
   #)
<$/Component>

Advantages with the above are:

Disadvantages with the above are:


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: No Installation Registration[Next]: Uninstall Fails (Don't Panic)


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Friday October 13 2017 at 2:08pm
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.