/// <summary> /// Returns the version string and language string in the format that the installer /// expects to find them in the database. If you just want version information, set /// lpLangBuf and pcchLangBuf to zero. If you just want language information, set /// lpVersionBuf and pcchVersionBuf to zero. /// </summary> /// <param name="filePath">Specifies the path to the file.</param> /// <param name="version">Returns the file version. Set to 0 for language information only.</param> /// <param name="language">Returns the file language. Set to 0 for version information only.</param> internal static void GetFileVersion(string filePath, out string version, out string language) { int versionLength = 20; int languageLength = 20; StringBuilder versionBuffer = new StringBuilder(versionLength); StringBuilder languageBuffer = new StringBuilder(languageLength); int error = MsiInterop.MsiGetFileVersion(filePath, versionBuffer, ref versionLength, languageBuffer, ref languageLength); if (234 == error) { versionBuffer.EnsureCapacity(++versionLength); languageBuffer.EnsureCapacity(++languageLength); error = MsiInterop.MsiGetFileVersion(filePath, versionBuffer, ref versionLength, languageBuffer, ref languageLength); } else if (1006 == error) { // file has no version or language, so no error error = 0; } if (0 != error) { throw new MsiException(error); } version = versionBuffer.ToString(); language = languageBuffer.ToString(); }