Search code examples
wixwindows-installerwix3.5dtfmsi-gui

Using DTF to install msi package


We are trying to use Microsoft.Deployment.WindowsInstaller dll (C#) and install the MSI package. I couldn't find much examples regarding this. The installation is successfull. In case of error I want to display the error message in specific language using lcid. so I use the below method passing the error code. The MSI used has language English.

// Sample code for installing
        try
        {
            Installer.InstallProduct(@"Sample.msi", "ALLUSERS=1 ADDLOCAL=ALL");
        }
        catch (InstallCanceledException ex)
        {
            errorList.Add(ex.ErrorCode + " " + ex.Message);

        }
        catch (InstallerException ex)
        {
            errorList.Add("Exit Code: " + ex.ErrorCode + ", " + ex.Message);
            // Translate error message to different language
            // ex.GetErrorRecord is always null,so the below method doesn't work.
            string langError = Installer.GetErrorMessage(ex.GetErrorRecord(),System.Globalization.CultureInfo.GetCultureInfo(1031));
        }

Am I using the method right? Please provide / point me to example where I can get the correct error message in specific language.

Thanks an lot in advance.


Solution

  • You should show more of your code so we can see where you're getting that error from, so some of this may be what you're already doing.

    If you use Installer.InstallProduct then you get an InstallerException if it fails, and that already contains a Message as well as an ErrorCode. Basically you need the result from (underneath everything) the call to MsiInstallProduct, and this is the list including your 1603:

    https://msdn.microsoft.com/en-us/library/aa368542(v=vs.85).aspx

    But you are using the error message function that returns errors during the actual install that includes the "file in use" 1603:

    https://msdn.microsoft.com/en-us/library/aa372835(v=vs.85).aspx

    You may have done all this, if so, then your question may be about how you get the error message from the InstallerException in the appropriate language. So maybe you need to call the GetErrorMessage overload that uses GetErrorRecord from the InstallerException and the culture info as parameters.