将应用程序启动选项(复选框)添加到安装

Vis*_*har 2 c# windows-installer setup-deployment

我在.Net中开发了我的应用程序,我的安装程序运行正常.

现在我想要一些更多功能,例如在安装程序末尾添加复选框,以便在单击完成按钮后启动相同的应用程序.

我还实现了此处给出的步骤:如何在Visual Studio安装/部署项目中自定义MSI? 但最终无法获得复选框.

现有的JScript是这样的:

   // EnableLaaunchApplication.js <msi-file>
   // Performs a post-build fixup of an msi to launch a specific file when the install has completed


   // Configurable values
   var checkboxChecked = true;          // Is the checkbox on the finished dialog checked by default?
   var checkboxText = "Launch [ProductName]";   // Text for the checkbox on the  finished dialog
   var filename = "FlashApp.exe";   // The name of the executable to launch - change this to match the file you want to launch at the end of your setup


   // 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

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


WScript.Echo("Updating the Control table...");
// Modify the Control_Next of BannerBmp control to point to the new CheckBox
sql = "SELECT `Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, `Attributes`, `Property`, `Text`, `Control_Next`, `Help` FROM `Control` WHERE `Dialog_`='FinishedForm' AND `Control`='BannerBmp'";
view = database.OpenView(sql);
view.Execute();
record = view.Fetch();
record.StringData(15) = "CheckboxLaunch";
view.Modify(msiViewModifyReplace, record);
view.Close();

// Resize the BodyText and BodyTextRemove controls to be reasonable
sql = "SELECT `Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, `Attributes`, `Property`, `Text`, `Control_Next`, `Help` FROM `Control` WHERE `Dialog_`='FinishedForm' AND `Control`='BodyTextRemove'";
view = database.OpenView(sql);
view.Execute();
record = view.Fetch();
record.IntegerData(7) = 33;
view.Modify(msiViewModifyReplace, record);
view.Close();

sql = "SELECT `Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, `Attributes`, `Property`, `Text`, `Control_Next`, `Help` FROM `Control` WHERE `Dialog_`='FinishedForm' AND `Control`='BodyText'";
view = database.OpenView(sql);
view.Execute();
record = view.Fetch();
record.IntegerData(7) = 33;
view.Modify(msiViewModifyReplace, record);
view.Close();

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



WScript.Echo("Updating the ControlEvent table...");
// 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 application
sql = "INSERT INTO `ControlEvent` (`Dialog_`, `Control_`, `Event`, `Argument`, `Condition`, `Ordering`) VALUES ('FinishedForm', 'CloseButton', 'DoAction', 'VSDCA_Launch', 'LAUNCHAPP=1', '0')";
view = database.OpenView(sql);
view.Execute();
view.Close();



WScript.Echo("Updating the CustomAction table...");
// Insert the custom action to launch the application when finished
sql = "INSERT INTO `CustomAction` (`Action`, `Type`, `Source`, `Target`) VALUES ('VSDCA_Launch', '210', '" + fileId + "', '')";
view = database.OpenView(sql);
view.Execute();
view.Close();



if (checkboxChecked)
{
    WScript.Echo("Updating the Property table...");
    // Set the default value of the CheckBox
    sql = "INSERT INTO `Property` (`Property`, `Value`) VALUES ('LAUNCHAPP', '1')";
    view = database.OpenView(sql);
    view.Execute();
    view.Close();
}



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



    function FindFileIdentifier(database, fileName)
    {
var sql
var view
var record

// First, try to find the exact file name
sql = "SELECT `File` FROM `File` WHERE `FileName`='" + fileName + "'";
view = database.OpenView(sql);
view.Execute();
record = view.Fetch();
if (record)
{
    var value = record.StringData(1);
    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`, `FileName` FROM `File`";
view = database.OpenView(sql);
view.Execute();
record = view.Fetch();
while (record)
{
    if (StringEndsWith(record.StringData(2), "|" + fileName))
    {
        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);
    }
Run Code Online (Sandbox Code Playgroud)

Chr*_*ter 7

您应该知道Visual Studio安装项目在很多方面都很糟糕.事实上,微软已将它们从Visual Studio 11中删除,并鼓励用户使用名为Limited Edition的免费版InstallShield.ISLE支持在完成对话框中添加一个复选框以启动您的应用程序.另一种可能性是转换为Windows Installer XML.这一切都取决于您的需求以及您希望投入学习安装程序的时间.

Visual Studio Setup Projects隐藏了很多基础MSI,它非常有限.有一些方法可以通过MSI的后期构建SQL更新来破解它,但它确实是后方的痛苦而不是可扩展的解决方案.

在我看来,这种脚本是毫无价值的努力.让我们用一个类比.如果您正在使用.NET langauge的一些实现(让我们称之为Bb)并且您发现它缺少一堆CLR/.NET功能,您是否会使用postbuild在生成的程序集中操作IL,或者只需切换到更好的CLR语言,如C#?这是同一件事.不要操纵结果MSI,切换到更好的工具.