1627-Microsoft.Deployment.WindowsInstaller.InstallerException:函数在执行期间失败

时间:2019-10-09 08:21:58

标签: c# windows-installer

现在,问题是,当我在创建的MSI文件上运行此代码时,最后一个查询(即,对于延迟启动的查询)失败,并为我提供了msi错误代码1627的异常:

Microsoft.Deployment.WindowsInstaller.InstallerException:函数在执行期间失败。    在Microsoft.Deployment.WindowsInstaller.View.Execute(记录executeParams)    在Microsoft.Deployment.WindowsInstaller.Database.Execute(String sql,记录记录)    在Microsoft.Deployment.WindowsInstaller.Database.Execute(String sqlFormat,Object [] args)    在C:\ Users \ Chirag Pathak \ 3D Objects \ bizbrain-agent-v7 \ Installers \ MSIManager \ Program.cs:line 96

下面是我的代码

   class Program
            {
                private static int msidbServiceConfigEventInstall = 1;
                private static int SERVICE_CONFIG_DELAYED_AUTO_START = 3;

                private static string BIN_FILE_PATH_X64 = @"C:\Users\Chirag Pathak\3D Objects\bizbrain-agent-v7\x64\Debug\";
                private static string MSI_NAME_X64 = "MyTallyApp Agent Installer (x64).msi";

                private static string PATH_PREFIX = "C:\\Users\\Chirag Pathak\\3D Objects\\bizbrain-agent-v7\\Installers\\Installers\\";

        static void Main(string[] args)
                {
                    UpdateMSIService(MSI_NAME_X64, "BizBrainAgentWindowsService-x64", "MyTallyApp Agent Service (64 bit)", "BizBrainAgentWindowsService-x64.exe");
                    UpdateMSIService(MSI_NAME_X64, "BizBrainAgentWindowsServiceLauncher-x64", "MyTallyApp Agent Service Launcher (64 bit)", "BizBrainAgentWindowsServiceLauncher-x64.exe");

                }

              static bool UpdateMSIService(string msi, string serviceName, string displayName, string fileName)
                {
                    string databasePath = PATH_PREFIX + msi;
                    if (!File.Exists(databasePath))
                    {
                        Console.WriteLine("MSI File " + msi + " does not exist!");   
                        return false;
                    }

                    using(Database database = new Database(databasePath, DatabaseOpenMode.Direct))
                    {
                        try
                        {
                            serviceName = "'" + serviceName + "'";
                            displayName = "'" + displayName + "'";

                            Microsoft.Deployment.WindowsInstaller.View view = database.OpenView("Select Component_,FileName from File");
                            view.Execute();
                            Record[] records = view.ToArray<Record>();
                            string componentId = "'" + GetComponentId(records, fileName) + "'";
                            view.Close();
                            Console.WriteLine("Service ComponentId=:" + componentId);
                            //Do this after the search
                            fileName = "'" + fileName + "'";

                            string sqlDeleteServiceInstall = "DELETE FROM `ServiceInstall` WHERE `ServiceInstall`=" + serviceName;
                            database.Execute(sqlDeleteServiceInstall);


                            string sqlInsertServiceInstall = "INSERT INTO `ServiceInstall` (`ServiceInstall`,`Name`,`DisplayName`,`ServiceType`,`StartType`,`ErrorControl`,`Component_`,`Description`) VALUES (" + serviceName + "," + serviceName + "," + displayName + ",16,2,1," + componentId + "," + displayName + ")";
                            database.Execute(sqlInsertServiceInstall);

                            string sqlDeleteServiceControl = "DELETE FROM `ServiceControl` WHERE `ServiceControl`=" + serviceName;
                            database.Execute(sqlDeleteServiceControl);

                            string sqlInsertServiceControl = "INSERT INTO `ServiceControl` (`ServiceControl`,`Name`,`Event`,`Component_`) VALUES(" + serviceName + "," + serviceName + ",1," + componentId + ")"; 
                            database.Execute(sqlInsertServiceControl);


                  ****//For Automatic [Delayed Start]
                                string sqlInsertMSIServiceConfig = "INSERT INTO `MsiServiceConfig`(`MsiServiceConfig`,`Name`,`Event`,`ConfigType`,`Argument`,`Component_`) VALUES('AutoStartDelayed'," + serviceName + "," + msidbServiceConfigEventInstall + "," + SERVICE_CONFIG_DELAYED_AUTO_START + ",1," + componentId + ")";  
                                database.Execute(sqlInsertMSIServiceConfig);//****//This is the line where exception occures.
                            return true;

                        }
                        catch (Exception e)
                        { }
                    }  
                }

{“ msiErrorCode”:1627,“ ClassName”:“ Microsoft.Deployment.WindowsInstaller.InstallerException”,“ Message”:“执行期间函数失败。”,“ Data”:null,“ InnerException”:null,“ HelpURL “ .null,“ StackTraceString”:“在Microsoft.Deployment.WindowsInstaller.View.Execute(记录executeParams)\ r \ n在Microsoft.Deployment.WindowsInstaller.Database.Execute(字符串sql,记录记录)\ r \ n在Microsoft .Deployment.WindowsInstaller.Database.Execute(String sqlFormat,Object [] args)\ r \ n在C:\ Users \ Chirag Pathak \ 3D中的MSIManager.Program.UpdateMSIService(String msi,String serviceName,String displayName,String fileName) Objects \ bizbrain-agent-v7 \ Installers \ MSIManager \ Program.cs:line 96“,” RemoteStackTraceString“:null,” RemoteStackIndex“:0,” ExceptionMethod“:” 8 \ nExecute \ nMicrosoft.Deployment.WindowsInstaller,版本= 3.0 .0.0,区域性=中性,PublicKeyToken = ce35f76fcda82bad \ nMicrosoft.Deployment.WindowsInstaller.View \ nVoid Execute(Microsoft.Deployment.WindowsInstaller.Record)“,” HResult“:-214623308 7,“ Source”:“ Microsoft.Deployment.WindowsInstaller”,“ WatsonBuckets”:null}

0 个答案:

没有答案