When building an installer for a Java desktop application, I needed to leave a script installed that could re-create a lost desktop shortcut by just clicking the script. I came across a VBScript (mkshortcut.vbs) that does what I wanted:

Set Shell = CreateObject("WScript.Shell")
DesktopPath = Shell.SpecialFolders("Desktop")
Set link = Shell.CreateShortcut(DesktopPath & "\MyApp.lnk")
link.Arguments = "Arg1 Arg2 Arg3"
link.Description = "A Tooltip"
link.HotKey = "CTRL+ALT+SHIFT+F"
link.IconLocation = "$INSTALL_PATH\images\MyApp.ico"
link.TargetPath = "$INSTALL_PATH\MyApp.jar"
link.WindowStyle = 1
link.WorkingDirectory = "$INSTALL_PATH"
link.Save

Let's assume this script is dropped into the bin/ directory of your $INSTALL_PATH when the IzPack installer does it's work. The trick is just to have IzPack replace $INSTALL_PATH in the script with the user-chosen install path and then have it automatically execute the script. This is accomplished with the following XML in your main application pack stanza.

<pack name="MyApp - Core" required="yes">
  <description></description>
  <fileset dir="dist" targetdir="$INSTALL_PATH">
    <include name="bin/mkshortcut.vbs"/>
    <include name="MyApp.jar"/>
    <include name="bin/MyApp.ico"/>
  </fileset>
  <parsable targetfile="$INSTALL_PATH/bin/mkshortcut.vbs"/>
  <executable os="windows" keep="true" failure="warn" stage="postinstall"
    targetfile="wscript.exe">
    <args>
      <arg value="$INSTALL_PATH/bin/mkshortcut.vbs"/>
    </args>
  </executable>
</pack>

Welcome!

I am a software developer from Calgary, Canada. I like to dabble in open-source software when not slinging Java at my day job.

You're currently only seeing the public areas of my site. For access to personal photos, videos, and blog posts, you'll need to login.

Around the Web

Recent Blog Posts

tech blog%> Google releases App Inventor framework
2010-07-12 at 12:51 pm
play blog%> Why Geo-Exchange Heating?
2010-06-21 at 12:52 pm
play blog%> Why Solar Hot Water?
2010-06-21 at 12:51 pm
play blog%> Why build Green?
2010-06-21 at 12:49 pm
play blog%> Basement development
2010-06-10 at 09:18 pm
play blog%> Welcoming Connor Davis
2010-05-14 at 11:37 am
play blog%> Mechanical systems and siding progressing
2010-04-21 at 07:34 pm
play blog%> Feds shut down housing efficiency program
2010-04-04 at 01:11 pm

Recent Comments

Listening To