VS2019 Setup Project

netasp 21 Reputation points
2020-12-09T16:47:39.267+00:00

Guys,

I have a VB.NET project designed in VS2019, I have built my Setup Project and the build installs successfully. I find myself always running the following command after the installation from the Run command on Windows 10:

C:\MyProject\Temp.exe /regserver

How can I embed this command so it can run automatically once I install my project. I have tried the PostBuildEvent and tried to add /regserver as an argument to the primary output on custom actions --> commit but nothing seems to work.

Any idea?

Thanks

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,603 questions
{count} votes

Accepted answer
  1. RLWA32 40,286 Reputation points
    2020-12-10T21:27:58.72+00:00

    I cobbled this script together from some bits and pieces of other work that I've done. It can be run as a post-build event in a visual studio installer project. Place the script into the same folder that contains the installer project (.vdproj). The post-build event should run

    cscript.exe "$(ProjectDir)AddCOMRegistration.js" "$(BuiltOuputPath)"
    

    Before running the script you should edit it to insert the name of the COM server that will be installed by the .msi file. I haven't tested it extensively, but it worked properly in a limited test to add COM registration/unregistration to an installer project that set the vsdrpDoNotRegister property on the COM Server project's primary output.

    This is the script -

    // AddCOMRegistration.js <msi-file>
    // Performs a post-build fixup of an msi to register/unregister out-of-process (.exe) COM Server
    
    
    // Configurable values
    var filename = "YourCOMServer.exe"; // The name of the executable COM server - change this to match the server you want to register
    
    
    // Constant values from Windows Installer
    var msiOpenDatabaseModeTransact = 1;
    
    var msiViewModifyInsert         = 1
    var msiViewModifyUpdate         = 2
    var msiViewModifyAssign         = 3
    var msiViewModifyReplace        = 4
    var msiViewModifyDelete         = 6
    
    
    
    if (WScript.Arguments.Length != 1)
    {
        WScript.StdErr.WriteLine(WScript.ScriptName + " file");
        WScript.Quit(1);
    }
    
    var filespec = WScript.Arguments(0);
    var installer = WScript.CreateObject("WindowsInstaller.Installer");
    var database = installer.OpenDatabase(filespec, msiOpenDatabaseModeTransact);
    
    var sql
    var view
    var record
    var componentId
    
    try
    {
        fileId = FindFileIdentifier(database, filename);
        if (!fileId)
            throw "Unable to find '" + filename + "' in File table";
    
    
    
        WScript.Echo("Updating the CustomAction table...");
        var caReg = "EXEREG_CA_" + fileId
        sql = "INSERT INTO `CustomAction` (`Action`, `Type`, `Source`, `Target`) VALUES ('" + caReg + "', '3154', '" + fileId + "', '/REGSERVER')";
        view = database.OpenView(sql);
        view.Execute();
        view.Close();
    
        var caUnreg = "EXEUNREG_CA_" + fileId
        sql = "INSERT INTO `CustomAction` (`Action`, `Type`, `Source`, `Target`) VALUES ('" + caUnreg + "', '3154', '" + fileId + "', '/UNREGSERVER')";
        view = database.OpenView(sql);
        view.Execute();
        view.Close();
    
        WScript.Echo("Updating the InstallExecuteSequence table...")
        var condReg = "$" + componentId + ">2";
        sql = "INSERT INTO `InstallExecuteSequence` (`Action`, `Condition`, `Sequence`) VALUES ('" + caReg + "', '" + condReg + "', '5601')";
        view = database.OpenView(sql);
        view.Execute();
        view.Close();
    
        var condUnreg = "$" + componentId + "=2";
        sql = "INSERT INTO `InstallExecuteSequence` (`Action`, `Condition`, `Sequence`) VALUES ('" + caUnreg + "', '" + condUnreg + "', '2201')";
        view = database.OpenView(sql);
        view.Execute();
        view.Close();
    
        database.Commit();
    }
    catch(e)
    {
        WScript.StdErr.WriteLine(e);
        WScript.Quit(1);
    }
    
    
    // Finds file id and component id of file
    function FindFileIdentifier(database, fileName)
    {
        var sql
        var view
        var record
    
        // First, try to find the exact file name
        sql = "SELECT `File`, `Component_` FROM `File` WHERE `FileName`='" + fileName + "'";
        view = database.OpenView(sql);
        view.Execute();
        record = view.Fetch();
        if (record)
        {
            var value = record.StringData(1);
            componentId = record.StringData(2)
            view.Close();
            return value;
        }
        view.Close();
    
        // The file may be in SFN|LFN format.  Look for a filename in this case next
        sql = "SELECT `File`, `Component_`, `FileName` FROM `File`";
        view = database.OpenView(sql);
        view.Execute();
        record = view.Fetch();
        while (record)
        {
            if (StringEndsWith(record.StringData(3), "|" + fileName))
            {
                componentId = record.StringData(2);
                var value = record.StringData(1);
                view.Close();
                return value;
            }
    
            record = view.Fetch();
        }
        view.Close();
    
    }
    
    function StringEndsWith(str, value)
    {
        if (str.length < value.length)
            return false;
    
        return (str.indexOf(value, str.length - value.length) != -1);
    }
    

2 additional answers

Sort by: Most helpful
  1. RLWA32 40,286 Reputation points
    2020-12-10T11:15:57.45+00:00

    I have noticed that when the Visual Studio Installer Projects extension creates the .msi for an unmanaged out-of-process COM Server (.exe) and the "Register" property is set to vsdrpCOM that a warning message is issued to inform that the extension was unable to create the registration information for the server. A subsequent installation using the generated .msi will not register the COM server.

    However, if the property is changed to vsdrpCOMSelfReg then the .msi builds without the warning message and the COM Server is registered upon installation. Examining the .msi file with Orca indicates that the installer project created the necessary custom actions in the .msi to register/unregister the COM server. For example, -

    46944-orca.png

    1 person found this answer helpful.

  2. Dylan Zhu-MSFT 6,406 Reputation points
    2020-12-10T03:58:02.56+00:00

    Hi netasp,

    You could try to create a executable file to run Temp.exe or bat file, then add it into a custom action of installation. Please follow this document: https://www.codeproject.com/Articles/19560/Launching-Your-Application-After-Install-using-Vis

    Best Regards,
    Dylan


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our **documentation to enable e-mail notifications if you want to receive the related email notification for this thread.**