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

C# 将应用程序启动选项(复选框)添加到安装,c#,windows-installer,setup-deployment,C#,Windows Installer,Setup Deployment,我已经在.Net中开发了我的应用程序,我的安装程序运行良好 现在我想要一些更多的功能,比如在安装程序末尾添加复选框,以便在单击finish按钮后启动相同的应用程序 我还实现了这里给出的步骤:但无法在最后获得复选框 现有的JScript如下所示: // EnableLaaunchApplication.js <msi-file> // Performs a post-build fixup of an msi to launch a specific file when t

我已经在.Net中开发了我的应用程序,我的安装程序运行良好

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

我还实现了这里给出的步骤:但无法在最后获得复选框

现有的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);
    }
//EnableLaaunchApplication.js
//执行msi的构建后修复,以在安装完成时启动特定文件
//可配置值
var checkboxChecked=true;//默认情况下是否选中“完成”对话框上的复选框?
var checkboxText=“启动[ProductName]”;//完成对话框上复选框的文本
var filename=“FlashApp.exe”;//要启动的可执行文件的名称-更改此名称以匹配安装结束时要启动的文件
//Windows Installer中的常量值
var msiOpenDatabaseModeTransact=1;
var msiViewModifyInsert=1
var msiViewModifyUpdate=2
变量msiViewModifyAssign=3
变量msiViewModifyReplace=4
var msiViewModifyDelete=6
if(WScript.Arguments.Length!=1)
{
WScript.StdErr.WriteLine(WScript.ScriptName+“文件”);
WScript.Quit(1);
}
var filespec=WScript.Arguments(0);
var installer=WScript.CreateObject(“WindowsInstaller.installer”);
var database=installer.OpenDatabase(filespec,msiOpenDatabaseModeTransact);
var-sql
变量视图
var记录
尝试
{
var fileId=FindFileIdentifier(数据库,文件名);
如果(!fileId)
在文件表中抛出“找不到“+”文件名“+”;
Echo(“更新控制表…”);
//修改BannerBmp控件旁边的控件_,以指向新复选框
sql=“选择`Dialog`、`Control`、`Type`、`X`、`Y`、`Width`、`Height`、`Attributes`、`Property`、`Text`、`Control`u Next`、`Help`来自`Control`其中`Dialog`=`FinishedForm`和`Control`='BannerBmp';
视图=数据库.OpenView(sql);
view.Execute();
record=view.Fetch();
record.StringData(15)=“CheckboxLaunch”;
查看.修改(msiViewModifyReplace,记录);
view.Close();
//调整BodyText和BodyTextRemove控件的大小使其合理
sql=“选择'Dialog'、'Control'、'Type'、'X'、'Y'、'Width'、'Height'、'Attributes'、'Property'、'Text'、'Control'u Next'、'Help`从'Control'中选择,其中'Dialog'='FinishedForm'和'Control'='BodyTextRemove';
视图=数据库.OpenView(sql);
view.Execute();
record=view.Fetch();
记录。整数数据(7)=33;
查看.修改(msiViewModifyReplace,记录);
view.Close();
sql=“选择`Dialog`、`Control`、`Type`、`X`、`Y`、`Width`、`Height`、`Attributes`、`Property`、`Text`、`Control`u Next`、`Help`FROM`Control`其中`Dialog`='FinishedForm`和`Control`='BodyText`”;
视图=数据库.OpenView(sql);
view.Execute();
record=view.Fetch();
记录。整数数据(7)=33;
查看.修改(msiViewModifyReplace,记录);
view.Close();
//插入新的复选框控件
sql=“插入到`Control`(`Dialog`、`Control`、`Type`、`X`、`Y`、`Width`、`Height`、`Attributes`、`Property`、`Text`、`Control_Next`、`Help`)值(`FinishedForm`、`CheckboxLaunch`、`CheckboxLaunch`、`18`、`117`、`343`、`X`、`3`、`LAUNCHAPP`、`VSI\u MS\u Sans\u Serif13.0\u 0}、`checkboxText+`、`CloseButton`、`124')”)”);
视图=数据库.OpenView(sql);
view.Execute();
view.Close();
Echo(“更新ControlEvent表…”);
//将FinishedForm的EndDialog事件的顺序修改为1
sql=“从`ControlEvent`中选择`Dialog`、`Control`、`Event`、`Argument`、`Condition`、`Ordering`,其中`Dialog`='FinishedForm'和`Event`='EndDialog'”;
视图=数据库.OpenView(sql);
view.Execute();
record=view.Fetch();
记录。整数数据(6)=1;
查看.修改(msiViewModifyReplace,记录);
view.Close();
//插入事件以启动应用程序
sql=“插入到`ControlEvent`(`Dialog`、`Control`、`Event`、`Argument`、`Condition`、`Ordering`)值中('FinishedForm'、'CloseButton'、'DoAction'、'VSDCA_Launch'、'LAUNCHAPP=1'、'0');
视图=数据库.OpenView(sql);
view.Execute();
view.Close();
Echo(“更新CustomAction表…”);
//插入自定义操作以在完成时启动应用程序
sql=“插入到`CustomAction`(`Action`、`Type`、`Source`、`Target`)值('VSDCA_Launch','210','“+fileId+”,'');
视图=数据库.OpenView(sql);
view.Execute();
view.Close();
如果(复选框已选中)
{
Echo(“更新属性表…”);
//设置复选框的默认值
sql=“插入'Property'('Property','Value`)值('LAUNCHAPP','1')”;
视图=数据库.OpenView(sql);
view.Execute();
view.Close();
}
Commit();
}
捕获(e)
{
WScript.StdErr.WriteLine(e);
WScript.Quit(1);
}
函数FindFileIdentifier(数据库,文件名)
{
var-sql
变量视图
var记录
//首先,尝试查找确切的文件名
sql=“从`File`中选择`File`,其中`FileName`='+FileName+”;
视图=数据库.OpenView(sql);
view.Execute();
record=view.Fetch();
如果(记录)
{
var值=记录.StringData(1);
view.Close();
返回值;
}
view.Close();
//该文件可能是SFN | LFN格式。接下来在本例中查找文件名
sql=“从“文件”中选择“文件”和“文件名”;
视图=数据库.OpenView(sql);
view.Execute();
record=view.Fetch();
while(记录)
{
if(StringEndsWith(record.StringData(2),“|”+文件名))
{
var值=记录.StringData(1);
view.Close();
返回值;
}
record=view.Fetch();
}
view.Close();
}
函数StringEndsWith(str,value)
{
如果(str.length
您应该知道Visual Studio安装项目在很多方面都很糟糕。事实上,微软已经将它们从VisualStudio11中删除,并鼓励用户使用