使用参数调用C#CA时无法调用command.exe(SQL Server Setup.exe)

开发人员环境:Wix 3.10,Visual Studio 2010(带有Wix扩展),Windows 7 x64

我想创建一个SQL Server实例安装程序(将固定参数传递给Microsoft官方安装程序Setup.exe

即使在阅读如何使用WiX将CustomActionData传递给CustomAction后,我也未能使用参数调用C#延迟的CustomAction ? 。 我认为安装SQL Server需要提升状态,因此我需要延迟操作。

似乎安装程序正在停止,而msi在JIT调试代码之前调用C# CustomAction (System.Diagnostics.Debugger.Break)有时会发生明显错误(通常在使用详细日志模式调用msi时)“Windows Host Process(Rundll32)停止“。

Msi SELECT Message错误可能是运行时错误的原因之一,但似乎错误的主要原因是缺少用户权限或x86 / x64兼容性?,或者我的愚蠢错误……任何想法?

以下是与此问题相关的wxs和cs文件的一部分:

CallSQLSvrInstallDlg.wxs

     ~Snip~           <!--    -->                           1 1    

CustomizedVerifyReadyDlg.wxs

        1   ~Snip~     

CustomAction.cs

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using WinForms = System.Windows.Forms; using System.IO; using Microsoft.Deployment.WindowsInstaller; using System.Threading; public class CustomActions { ~Snip~ [CustomAction] public static ActionResult ExecuteSQLServerInstanceInstall(Session session) { try { System.Diagnostics.Debugger.Break(); session.Log("Begin ExecuteSQLServerInstanceInstall Custom Action"); var task = new Thread(() => ExecuteByDOSCommand(session)); task.SetApartmentState(ApartmentState.STA); task.Start(); task.Join(); session.Log("End ExecuteSQLServerInstanceInstall Custom Action"); } catch (Exception ex) { session.Log("Exception occurred as Message: {0}\r\n StackTrace: {1}", ex.Message, ex.StackTrace); return ActionResult.Failure; } return ActionResult.Success; } private static void ExecuteByDOSCommand(Session session) { string condition_str = null; condition_str = session.CustomActionData["INSTALLCONDITIONPARAMS"]; //  string SaPassword = null; string SetupExePath = null; string X64RootPath = null; string X86RootPath = null; //string InstanceType = null; string InstanceName = null; string SysAdCurWinUser = null; string CurrentWinUser = null; string ExecuteCmd = null; string[] stArrayData = condition_str.Split('|'); for(int i=0; i{0}", e.Data); } } 

详细日志中的错误代码如下:

 {Snip} MSI (c) (58:18) [10:41:17:968]: Note: 1: 2205 2: 3: Error MSI (c) (58:18) [10:41:17:968]: Note: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 2898 Info 2898.For WixUI_Font_Normal textstyle, the system created a 'Tahoma' font, in 128 character set, of 13 pixels height. MSI (c) (58:18) [10:41:17:968]: Note: 1: 2205 2: 3: Error MSI (c) (58:18) [10:41:17:968]: Note: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 2898 Info 2898.For WixUI_Font_Bigger textstyle, the system created a 'Tahoma' font, in 128 character set, of 19 pixels height. {Snip} MSI (c) (58:C0) [10:41:18:019]: Note: 1: 2205 2: 3: _RemoveFilePath MSI (c) (58:C0) [10:41:18:019]: PROPERTY CHANGE: Modifying CostingComplete property. Its current value is '0'. Its new value: '1'. MSI (c) (58:C0) [10:41:18:019]: Note: 1: 2205 2: 3: Registry MSI (c) (58:C0) [10:41:18:019]: Note: 1: 2205 2: 3: BindImage MSI (c) (58:C0) [10:41:18:019]: Note: 1: 2205 2: 3: ProgId MSI (c) (58:C0) [10:41:18:019]: Note: 1: 2205 2: 3: PublishComponent MSI (c) (58:C0) [10:41:18:019]: Note: 1: 2205 2: 3: SelfReg MSI (c) (58:C0) [10:41:18:019]: Note: 1: 2205 2: 3: Extension MSI (c) (58:C0) [10:41:18:019]: Note: 1: 2205 2: 3: Font MSI (c) (58:C0) [10:41:18:019]: Note: 1: 2205 2: 3: Shortcut MSI (c) (58:C0) [10:41:18:019]: Note: 1: 2205 2: 3: Class MSI (c) (58:C0) [10:41:18:019]: Note: 1: 2205 2: 3: Icon MSI (c) (58:C0) [10:41:18:019]: Note: 1: 2205 2: 3: TypeLib MSI (c) (58:C0) [10:41:18:020]: Note: 1: 2727 2: MSI (c) (58:18) [10:41:19:305]: Note: 1: 2205 2: 3: Error MSI (c) (58:18) [10:41:19:305]: Note: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 2898 Info 2898.For WixUI_Font_Title textstyle, the system created a 'Tahoma' font, in 128 character set, of 14 pixels height. {Snip} MSI (s) (5C:5C) [10:41:23:678]: Machine policy value 'DisableUserInstalls' is 0 MSI (s) (5C:5C) [10:41:23:689]: Machine policy value 'LimitSystemRestoreCheckpointing' is 0 MSI (s) (5C:5C) [10:41:23:689]: Note: 1: 1715 2: SQL Server for FugaFuga MSI (s) (5C:5C) [10:41:23:689]: Note: 1: 2205 2: 3: Error MSI (s) (5C:5C) [10:41:23:689]: Note: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1715 MSI (s) (5C:5C) [10:41:23:689]: Calling SRSetRestorePoint API. dwRestorePtType: 0, dwEventType: 102, llSequenceNumber: 0, szDescription: "Installed SQL Server for FugaFuga". MSI (s) (5C:5C) [10:41:34:534]: The call to SRSetRestorePoint API succeeded. Returned status: 0, llSequenceNumber: 342. MSI (s) (5C:5C) [10:41:34:537]: File will have security applied from OpCode. {Snip} MSI (s) (5C:5C) [10:41:38:885]: Adding new sources is allowed. MSI (s) (5C:5C) [10:41:38:885]: PROPERTY CHANGE: Adding PackagecodeChanging property. Its value is '1'. MSI (s) (5C:5C) [10:41:38:886]: Package name extracted from package path: 'SQLServerInstaller.msi' MSI (s) (5C:5C) [10:41:38:886]: Package to be registered: 'SQLServerInstaller.msi' MSI (s) (5C:5C) [10:41:38:886]: Note: 1: 2205 2: 3: Error MSI (s) (5C:5C) [10:41:38:889]: Note: 1: 2262 2: AdminProperties 3: -2147287038 MSI (s) (5C:5C) [10:41:38:889]: Machine policy value 'AlwaysInstallElevated' is 0 MSI (s) (5C:5C) [10:41:38:889]: User policy value 'AlwaysInstallElevated' is 0 MSI (s) (5C:5C) [10:41:38:889]: Running product '{BFAE49AD-07EF-454F-A1B5-1A90E8015138}' with elevated privileges: Proper credentials provided for LUA. MSI (s) (5C:5C) [10:41:38:889]: PROPERTY CHANGE: Adding INSTALLDIR property. Its value is 'C:\Program Files (x86)\HogeHoge\HogeHoge Service\'. MSI (s) (5C:5C) [10:41:38:889]: PROPERTY CHANGE: Modifying INSTANCESTATUS property. Its current value is '0'. Its new value: '1'. MSI (s) (5C:5C) [10:41:38:889]: PROPERTY CHANGE: Adding CURRENTWINUSER property. Its value is '{Domain Name}\{User Name}'. MSI (s) (5C:5C) [10:41:38:889]: PROPERTY CHANGE: Adding VERIFYDLGMSG property. Its value is 'FugaFuga_for_web {Snip} MSI (s) (5C:5C) [10:41:42:835]: Note: 1: 2205 2: 3: Error MSI (s) (5C:5C) [10:41:42:835]: Note: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1302 MSI (s) (5C:5C) [10:41:42:835]: Note: 1: 2205 2: 3: MsiSFCBypass MSI (s) (5C:5C) [10:41:42:835]: Note: 1: 2228 2: 3: MsiSFCBypass 4: SELECT `File_` FROM `MsiSFCBypass` WHERE `File_` = ? MSI (s) (5C:5C) [10:41:42:835]: Note: 1: 2205 2: 3: MsiPatchHeaders MSI (s) (5C:5C) [10:41:42:835]: Note: 1: 2228 2: 3: MsiPatchHeaders 4: SELECT `Header` FROM `MsiPatchHeaders` WHERE `StreamRef` = ? MSI (s) (5C:5C) [10:41:42:837]: Note: 1: 2205 2: 3: PatchPackage MSI (s) (5C:5C) [10:41:42:837]: Note: 1: 2205 2: 3: MsiPatchHeaders MSI (s) (5C:5C) [10:41:42:837]: Note: 1: 2205 2: 3: PatchPackage Action ended 10:41:42: InstallFiles. Return value 1. MSI (s) (5C:5C) [10:41:42:839]: Doing action: RegisterUser MSI (s) (5C:5C) [10:41:42:839]: Note: 1: 2205 2: 3: ActionText Action 10:41:42: RegisterUser. Registering user Action start 10:41:42: RegisterUser. Action ended 10:41:42: RegisterUser. Return value 1. MSI (s) (5C:5C) [10:41:42:844]: Doing action: RegisterProduct MSI (s) (5C:5C) [10:41:42:844]: Note: 1: 2205 2: 3: ActionText Action 10:41:42: RegisterProduct. Registering product Action start 10:41:42: RegisterProduct. MSI (s) (5C:5C) [10:41:42:847]: Note: 1: 2205 2: 3: Error MSI (s) (5C:5C) [10:41:42:847]: Note: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1302 RegisterProduct: Registering product MSI (s) (5C:5C) [10:41:42:851]: PROPERTY CHANGE: Adding ProductToBeRegistered property. Its value is '1'. Action ended 10:41:42: RegisterProduct. Return value 1. MSI (s) (5C:5C) [10:41:42:852]: Doing action: PublishFeatures MSI (s) (5C:5C) [10:41:42:852]: Note: 1: 2205 2: 3: ActionText Action 10:41:42: PublishFeatures. Publishing Product Features Action start 10:41:42: PublishFeatures. {Snip} MSI (s) (5C:5C) [10:41:42:945]: Executing op: CustomActionSchedule(Action=ExecuteSQLServerInstanceInstall,ActionType=3073,Source=BinaryData,Target=ExecuteSQLServerInstanceInstall,CustomActionData=INSTALLCONDITIONPARAMS=FugaFuga_for_web|E:\Setup.exe|C:\Program Files|C:\Program Files (x86)|0|MSSQL|0|{Domain Name}\{User Name}) MSI (s) (5C:44) [10:41:43:021]: Invoking remote custom action. DLL: C:\Windows\Installer\MSI7C77.tmp, Entrypoint: ExecuteSQLServerInstanceInstall MSI (s) (5C:68) [10:41:43:021]: Generating random cookie. MSI (s) (5C:68) [10:41:43:025]: Created Custom Action Server with PID 3236 (0xCA4). MSI (s) (5C:0C) [10:41:43:545]: Running as a service. MSI (s) (5C:0C) [10:41:43:548]: Hello, I'm your 32bit Elevated Non-remapped custom action server. SFXCA: Extracting custom action to temporary directory: C:\Windows\Installer\MSI7C77.tmp-\ SFXCA: Binding to CLR version v4.0.30319 Calling custom action InstallerCsharpModules!CustomActions.ExecuteSQLServerInstanceInstall SFXCA: RUNDLL32 returned error code: 255 CustomAction ExecuteSQLServerInstanceInstall returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox) Action ended 10:41:44: InstallFinalize. Return value 3. MSI (s) (5C:5C) [10:41:44:387]: User policy value 'DisableRollback' is 0 MSI (s) (5C:5C) [10:41:44:387]: Machine policy value 'DisableRollback' is 0 MSI (s) (5C:5C) [10:41:44:394]: Executing op: Header(Signature=1397708873,Version=500,Timestamp=1286493494,LangId=1033,Platform=589824,ScriptType=2,ScriptMajorVersion=21,ScriptMinorVersion=4,ScriptAttributes=1) MSI (s) (5C:5C) [10:41:44:394]: Executing op: DialogInfo(Type=0,Argument=1033) MSI (s) (5C:5C) [10:41:44:394]: Executing op: DialogInfo(Type=1,Argument=SQL Server for FugaFuga) MSI (s) (5C:5C) [10:41:44:395]: Executing op: RollbackInfo(,RollbackAction=Rollback,RollbackDescription=Rolling back action:,RollbackTemplate=[1],CleanupAction=RollbackCleanup,CleanupDescription=Removing backup files,CleanupTemplate=File: [1]) Action 10:41:44: Rollback. Rolling back action: Rollback: ExecuteSQLServerInstanceInstall {Snip} 

PS我克服了错误“Windows Host Process(Rundll32)已停止”。 通过从CustomAction“ExecuteSQLServerInstanceInstall”中删除“Impersonate = no”属性,但它可能不是SQL Server安装的正确解决方法……而且我不知道为什么在模拟中会发生此类错误。

我不确定这个问题是否应继续用于接下来的问题。

这个必须很短,我只是略过了你的问题。 第一:如何安装这些MSI文件? 你是从SCCM或其他一些分销系统中踢出来的吗? 几个一般指针:

无并发MSI安装 :Windows Installer不允许并发msiexec.exe会话。 换句话说, 两个MSI文件无法同时运行

  • 从技术上讲,它是无法同时运行的InstallExecuteSequence – MSI安装的提升部分 – 而不是GUI序列。 您可以启动两个MSI文件并进入GUI,但实际安装不能同时进行。
  • 结果是你无法启动MSI,而MSI又会启动任何其他MSI安装程序 – 或者随后启动MSI的EXE文件。 保证。 我怀疑这是你看到的问题 – 即使我不太熟悉SQL安装程序。
  • 过去有一个概念是通过自定义操作(称为嵌套MSI安装)或并发安装 (MSDN信息)启动嵌入式MSI – 但这已经过时并且被认为是徒劳的尝试。 如果你正在考虑它,那么我引用传奇的前安装盾支持队长罗伯特迪考“不要” 。 他多年经验的简明总结! :-)。
  • 对系统管理员编写的并发MSI安装相关问题的较旧解释 。 可能是一个更好的阅读。

WiX Bundle :与WiX一起使用的方法是使用Burn工具 – 一个自举程序,定序器,下载器function,它是WiX工具包的一部分。 它可以用于创建WiX Bundles:它是具有嵌入式MSI和EXE文件(以及其他部署文件)的包装EXE文件,能够按所需顺序按顺序安装文件。 可能需要一段时间才能习惯WiX标记和处理方式。 目前我没有为Burn提供大量样本,但这里有一些事情要做:

解压缩SQL安装程序 :也可以解压缩SQL setup.exe以提取嵌入式MSI文件和嵌入式EXE设置(而不是从WiX Bundle运行SQL setup.exe原始)。 如果目标环境是统一的,通常可以消除许多不必要的先决条件安装程序。 但是,我有疑问,因为处理这些核心MSI安装程序(SQL,.NET或任何核心Microsoft运行时或组件)的努力往往是不明智的,你应该尽可能“按原样”运行它们(你想要做的)。

其他工具 :商业工具(如Advanced Installer , Installshield , PACE Suite和其他一些工具)通常具有帮助安装重要运行时和组件(如这些工具)的function – 以防您拥有贵公司已有的工具。 这是我自己的部署工具和MSI(工具优缺点等)的编写: 如何创建Windows安装程序 。