简体   繁体   English

使用DTF安装MSI软件包

[英]Using DTF to install msi package

We are trying to use Microsoft.Deployment.WindowsInstaller dll (C#) and install the MSI package. 我们正在尝试使用Microsoft.Deployment.WindowsInstaller dll(C#)并安装MSI软件包。 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. 如果发生错误,我想使用lcid以特定语言显示错误消息。 so I use the below method passing the error code. 所以我使用下面的方法传递错误代码。 The MSI used has language English. 使用的MSI具有英语语言。

// 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. 非常感谢。

The API you are calling gets its messages from this list , not this one . 您正在调用的API从此列表 (而不是 列表)获取消息。

The API that will get you the message you are seeking can be accessed via the Win32Exception class (I'd make this a link, but I don't have enough points yet, although I'm sure you can find the class), but since you can't pass it an LCID, you will need to change your thread's culture, create the exception using your error code, then revert your thread's culture. 可以通过Win32Exception类访问将获取所需消息的API(我将其链接,但是我没有足够的积分,尽管我确定您可以找到该类),但是由于无法将其传递给LCID,因此您需要更改线程的区域性,使用错误代码创建异常,然后还原线程的区域性。

Hope this helps 希望这可以帮助

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. 如果您使用Installer.InstallProduct,则如果InstallerException失败,则会得到InstallerException,该异常已经包含Message和ErrorCode。 Basically you need the result from (underneath everything) the call to MsiInstallProduct, and this is the list including your 1603: 基本上,您需要从MsiInstallProduct调用(在所有内容下面)得到的结果,这是包括您的1603的列表:

https://msdn.microsoft.com/en-us/library/aa368542(v=vs.85).aspx https://msdn.microsoft.com/zh-CN/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: 但是您正在使用错误消息功能,该功能会在实际安装过程中返回错误,其中包括“正在使用的文件” 1603:

https://msdn.microsoft.com/en-us/library/aa372835(v=vs.85).aspx https://msdn.microsoft.com/zh-CN/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. 您可能已经完成了所有这些操作,如果是这样,那么您的问题可能是关于如何以适当的语言从InstallerException中获取错误消息。 So maybe you need to call the GetErrorMessage overload that uses GetErrorRecord from the InstallerException and the culture info as parameters. 因此,也许您需要调用GetErrorMessage重载,该重载使用InstallerException中的GetErrorRecord和区域性信息作为参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM