Reputation: 404
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.
Upvotes: 0
Views: 297
Reputation: 376
The API you are calling gets its messages from this list, not this one.
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.
Hope this helps
Upvotes: 2
Reputation: 20780
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.
Upvotes: 1