最近在討論區看到有關這樣的問題...小弟去找了一下資料..
介紹如何取得目前在執行的應用程式版本資訊,..
或者如何取得其它應用程式的版本資訊,例如NotePad.exe
一般在開發Application時,在組件資訊可以設定檔案或組件版本,如下圖所示:
還有一般我們在使用的其它應用程式,像NotePad.exe,都有版本資訊,如下圖所示:
那這些版本資訊,要如何用c#程式來取得呢....請看範例...
c#(部分程式碼)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Diagnostics;//記得using using System.Reflection;//記得using namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //取得目前應用程式版本 private void Form1_Load(object sender, EventArgs e) { this.Text ="Ver:"+ FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion.ToString(); } //取得NOTEPAD版本資訊 private void button1_Click(object sender, EventArgs e) { this.textBox1.Text = FileVersionInfo.GetVersionInfo(@"C:\WINDOWS\NOTEPAD.EXE").FileVersion.ToString(); } } }
執行結果:
參考網址:
http://blog.roodo.com/chhuang/archives/3158529.htmlhttp://msdn.microsoft.com/zh-tw/library/system.reflection.assembly.getexecutingassembly.aspxhttp://msdn.microsoft.com/en-us/library/system.diagnostics.fileversioninfo.getversioninfo.aspx