2

I have been following a solution to add a checkBox at the end of a MSI installation that opens the installed product :
Run exe after msi installation?

So far, so good. However, I'd like to add another checkBox that opens a simple text file which contains the release notes. The file is already included in the setup project, along with the main output. I'm able to add a new checkBox. The only problem is how to open that text file : no custom action seems to fit this need as I can see here : http://msdn.microsoft.com/en-us/library/windows/desktop/aa372048%28v=vs.85%29.aspx

Here's my current JS code :

var sql
var view
var checkboxTextForReleaseNotes = "See release notes";
var fileReleaseNotes = "ReleaseNotes.txt";

try
{
    var fileIdForReleaseNotes = FindFileIdentifier(database, fileReleaseNotes);
    if (!fileIdForReleaseNotes)
        throw "Unable to find '" + fileReleaseNotes + "' in File table";

    [ ... some actions to include another control as seen in link above ... ]

    // Insert the new CheckboxReleaseNotes control
    sql = "INSERT INTO `Control` (`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, `Attributes`, `Property`, `Text`, `Control_Next`, `Help`) VALUES ('FinishedForm', 'CheckboxReleaseNotes', 'CheckBox', '18', '140', '343', '12', '3', 'LAUNCH_RN', '{\\VSI_MS_Sans_Serif13.0_0_0}" + checkboxTextForReleaseNotes + "', 'CloseButton', '|')";
    view = database.OpenView(sql);
    view.Execute();
    view.Close();

    // Modify the Order of the EndDialog event of the FinishedForm to 1
    sql = "SELECT `Dialog_`, `Control_`, `Event`, `Argument`, `Condition`, `Ordering` FROM `ControlEvent` WHERE `Dialog_`='FinishedForm' AND `Event`='EndDialog'";
    view = database.OpenView(sql);
    view.Execute();
    record = view.Fetch();
    record.IntegerData(6) = 1;
    view.Modify(msiViewModifyReplace, record);
    view.Close();

    // Insert the Event to launch the release notes
    sql = "INSERT INTO `ControlEvent` (`Dialog_`, `Control_`, `Event`, `Argument`, `Condition`, `Ordering`) VALUES ('FinishedForm', 'CloseButton', 'DoAction', 'OPEN_RN', 'LAUNCH_RN=1', '0')";
    view = database.OpenView(sql);
    view.Execute();
    view.Close();

    // Insert the custom action to open the release notes when finished
    sql = "INSERT INTO `CustomAction` (`Action`, `Type`, `Source`, `Target`) VALUES ('OPEN_RN', '210', '" + fileIdForReleaseNotes + "', '')";
    view = database.OpenView(sql);
    view.Execute();
    view.Close();

    database.Commit();
}
catch (e)
{
    WScript.StdErr.WriteLine(e);
    WScript.Quit(1);
}

I know that type "210" for custom action is not the proper one ... but is there any ? Or must I really get through my way by launching a Jscript or VBScript ?

Editing : end of code completed. Tried also to add a custom action through the "vdproj" properties but it refuses because the file is not compatible.

Community
  • 1
  • 1
tjafaas
  • 21
  • 4

1 Answers1

0

All of the following is untested.

I think you want the custom action type 34 and also msidbCustomActionTypeAsync + msidbCustomActionTypeContinue to run it ASync/NoWait. So custom action type 34+192=226.

Source, according to the docs, doesn't have to be the same directory as the target executable.

Target is...

The Target column of the CustomAction table contains the full path and name of the executable file followed by optional arguments to the executable. The full path and name to the executable file is required. Quotation marks must be used around long file names or paths. The value is treated as formatted text and may contain references to properties, files, directories, or other formatted text attributes.

You can use the "start" shell command to load the text file using the shell. That will open the text file using the user's default text file viewer. You need the full path to start.exe and the full path to the release notes. Note how the docs say it will do string replacement on the Target field. There's a string format to get the full path to the a file given its File table key.

If a substring of the form [#filekey] is found, it is replaced by the full path of the file, with the value filekey used as a key into the File table.

Putting that all together, the following might work for Target:

"[SystemFolder]start.exe" "[#someFileKey]"

That all being said, if you're going to be doing more of these custom actions I would really look into Wix and authoring your own custom actions. Wix would save you from running this javascript post build. Authoring your own custom actions gives you direct access to either .NET or the Windows API. Opening a file with the shell in C#, for example, is pretty straight forward.

Community
  • 1
  • 1
  • Indeed WiX offers a lot more possibilities, but for the sake of the thread I'll try to finish this bit off. If I understand you correctly, the sql query should be as below, but doesn't work (no error pops out though): `sql = "INSERT INTO ``CustomAction`` (``Action``, ``Type``, ``Source``, ``Target``) VALUES ('OPEN_RN', '226', '', '\"[System]start.exe\" \"[#" + fileIdForReleaseNotes + "]\"')";` I'm not sure about the source though: can it be empty ? – tjafaas Apr 18 '13 at 14:23
  • Oops, it's [SystemFolder] not [System]. I was getting those values from [here](http://msdn.microsoft.com/en-us/library/windows/desktop/aa370905(v=vs.85).aspx). Docs say it ignores Source. Maybe leave [SystemFolder] in there and see if it changes things? Make sure your fileIdForReleaseNotes is correct. Open up the .MSI in Orca and look at the File table. What you want is the value in the File column. – Walter Wilfinger Apr 18 '13 at 18:04
  • You might also be getting hit with this part of the docs for [#filekey]: "The value of [#filekey] remains blank and is not replaced by a path until the installer runs the CostInitialize action, FileCost action, and CostFinalize action." – Walter Wilfinger Apr 18 '13 at 18:06
  • Not even explicit full path works: I tried the simple values as following and still not opening. `... VALUES ('OPEN_RN', '226', '', '\"C:\\Windows\\notepad.exe\" \"C:\\ReleaseNotes.txt\"')` Also, I deactivated the other checkbox in case of interference, so I'm testing with only this one and only checkbox. – tjafaas Apr 19 '13 at 08:23