ファイルのバージョン情報を取得する
スポンサーリンク
ファイルのバージョン情報は、System.Diagnostics.FileVersionInfo クラスから取得します。このクラスのインスタンスを生成するには、GetVersionInfo メソッドを使用します。
サンプルコード
以下にサンプルコードを示します。
C# 全般
// 指定したファイルのバージョン情報を取得する
System.Diagnostics.FileVersionInfo hVerInfo = (
System.Diagnostics.FileVersionInfo.GetVersionInfo(@"C:\WINDOWS\Notepad.exe")
);
string stNewLine = System.Environment.NewLine;
string stPrompt = string.Empty;
// ファイルまでのパス
stPrompt += "ファイル名 : " + hVerInfo.FileName + stNewLine;
// ファイルの説明 (AssemblyTitle)
stPrompt += "ファイルの説明 : " + hVerInfo.FileDescription + stNewLine;
// コメント (AssemblyDescription)
stPrompt += "コメント : " + hVerInfo.Comments + stNewLine;
// 会社名 (AssemblyCompany)
stPrompt += "会社名 : " + hVerInfo.CompanyName + stNewLine;
// 製品名 (AssemblyProduct)
stPrompt += "製品名 : " + hVerInfo.ProductName + stNewLine;
// 著作権 (AssemblyCopyright)
stPrompt += "著作権 : " + hVerInfo.LegalCopyright + stNewLine;
// 商標 (AssemblyTrademark)
stPrompt += "商標 : " + hVerInfo.LegalTrademarks + stNewLine;
// 正式ファイル名 (アセンブリ名)
stPrompt += "正式ファイル名 : " + hVerInfo.OriginalFilename + stNewLine;
// 内部名
stPrompt += "内部名 : " + hVerInfo.InternalName + stNewLine;
// 言語
stPrompt += "言語 : " + hVerInfo.Language + stNewLine);
// ファイルのバージョン情報
stPrompt += "ファイルのバージョン番号 : " + hVerInfo.FileVersion + stNewLine;
stPrompt += "ファイルのメジャー番号 : " + hVerInfo.FileMajorPart + stNewLine;
stPrompt += "ファイルのマイナ番号 : " + hVerInfo.FileMinorPart + stNewLine;
stPrompt += "ファイルのビルド番号 : " + hVerInfo.FileBuildPart + stNewLine;
stPrompt += "ファイルのプライベート番号 : " + hVerInfo.FilePrivatePart + stNewLine;
// 製品のバージョン情報
stPrompt += "製品のバージョン番号 : " + hVerInfo.ProductVersion + stNewLine;
stPrompt += "製品のメジャー番号 : " + hVerInfo.ProductMajorPart + stNewLine;
stPrompt += "製品のマイナ番号 : " + hVerInfo.ProductMinorPart + stNewLine;
stPrompt += "製品のビルド番号 : " + hVerInfo.ProductBuildPart + stNewLine;
stPrompt += "製品のプライベート番号 : " + hVerInfo.ProductPrivatePart + stNewLine;
// ビルド情報
stPrompt += "プライベート ビルド情報 : " + hVerInfo.PrivateBuild + stNewLine;
stPrompt += "特殊ビルド情報 : " + hVerInfo.SpecialBuild + stNewLine;
// その他の情報
stPrompt += "デバッグ情報を格納するか : " + hVerInfo.IsDebug + stNewLine;
stPrompt += "開発バージョン (プレリリース) か : " + hVerInfo.IsPreRelease + stNewLine;
stPrompt += "ファイルが変更されているか : " + hVerInfo.IsPatched + stNewLine;
stPrompt += "標準リリース プロシージャで生成されたか : " + hVerInfo.IsPrivateBuild + stNewLine;
stPrompt += "特殊ビルドかどうか : " + hVerInfo.IsSpecialBuild + stNewLine;
// 取得したすべてのバージョン情報を表示する
MessageBox.Show(stPrompt);
関連するリファレンス
準備中です。
