installshieldshortcutinstallscriptbasic-msi

Running into issue creating shortcut on desktop


I've just created a custom dialog with a checkbox asking if the user wants to create a desktop shortcut. I used to always include a shortcut I'm not using the AskText() function as I plan on adding more pieces to this page later and want to simplify these few options to this one page.

I get an item on my desktop when I run, but it's not what I expect. The target seems to be pointing to a location on the desktop itself and not the actual executable. Also, this shortcut does not delete on uninstall (I'm assuming this needs to be handled separately anyway) and the shortcut needs admin rights to be manually deleted (which I don't want, for obvious reasons).

Below is my InstallScript code. It is in a custom action that was inserted after InstallFiles.

function MyFunction(hMSI)

    STRING szProgramFolder, szItemName, szCommandLine, szWorkingDir;
    STRING szShortCutKey, szProgram, szParam, szIconPath;
    NUMBER nIcon, nResult;

begin
    szProgramFolder = FOLDER_DESKTOP;
    szItemName = "myProgram";

    szProgram = INSTALLDIR + "myProgram.exe" ;
    LongPathToQuote (szProgram, TRUE);
    szCommandLine = szProgram;

    szWorkingDir = INSTALLDIR;
    szIconPath = "";
    nIcon = 0;
    szShortCutKey = "";

    nResult = AddFolderIcon (szProgramFolder, szItemName, szCommandLine,szWorkingDir, 
      szIconPath, nIcon, szShortCutKey, REPLACE);

end;  

I'm not quite sure where I'm going wrong here, although my knowledge of InstallShield (let alone InstallScript) is very limited.


Solution

  • As it turned out, this is a deferred custom action, hence the INSTALLDIR variable is not initialized (nor any other Windows Installer built-in variables). Change it to an Immediate-type custom action (and relocate it to an appropriate location in the execution sequence) and it should work.