Use WiX properties in VBScript custom action

Nov 10, 2015 at 5:04 PM
Hi,

I try to add a ScriptAction to my collection of project.Actions. Is it possible to use properties values in my VB Script code string?
Like:
Set oShell = CreateObject ("Wscript.Shell")
oShell.CurrentDirectory = "[INSTALLDIR]"
It seems I cannot use the properties in the VB Script code.

Thanks.
Nov 11, 2015 at 4:23 AM
As far as I remember you cannot do this as VB script action is sandboxed. Though I can be wrong.

However you can achieve the same with the custom C# action:
public class CustomActions
{
    [CustomAction]
    public static ActionResult MyAction(Session session)
    {
        try
        {
            var p = new Process();
            p.StartInfo.WorkingDirectory = session["INSTALLDIR"];
            p.StartInfo.FileName = ...
            p.Start();
        }
        catch (Exception e)
        {
            session.Log(e.ToString());
            return ActionResult.Failure;
        }
        return ActionResult.Success;
    }
...
Or even simpler with the events (e.g. deferred actions):
project.AfterInstall += project_AfterInstall;
...
static void project_AfterInstall(SetupEventArgs e)
{
    try
    {
        var p = new Process();
        p.StartInfo.WorkingDirectory = e.InstallDir;
        p.StartInfo.FileName = ...
        p.Start();
    }
    catch (Exception ex)
    {
        e.Session.Log(ex.ToString());
    }
}
Have a look at "Managed Setup" samples for more details.