我不確定這是否可能。但是,如果我有地方存放.exe文件,我可以訪問它(例如,我的桌面),它具有存儲在文件的屬性的細節選項卡版本號變化(不談論gettable /可設置的屬性的編程結構在這裏)。我可以在.NET中訪問這個屬性嗎?是否可以在.NET中訪問外部程序的屬性?
我見過的所有的例子似乎引用本地程序屬性。
如果以上是不可能的,有沒有什麼辦法,使有關可用於其他程序訪問和讀取程序的某些信息?
編輯:我不只是要版本信息,我還需要在以後訪問修改日期和文件大小和其他可能的性質在細節選項卡上
我不確定這是否可能。但是,如果我有地方存放.exe文件,我可以訪問它(例如,我的桌面),它具有存儲在文件的屬性的細節選項卡版本號變化(不談論gettable /可設置的屬性的編程結構在這裏)。我可以在.NET中訪問這個屬性嗎?是否可以在.NET中訪問外部程序的屬性?
我見過的所有的例子似乎引用本地程序屬性。
如果以上是不可能的,有沒有什麼辦法,使有關可用於其他程序訪問和讀取程序的某些信息?
編輯:我不只是要版本信息,我還需要在以後訪問修改日期和文件大小和其他可能的性質在細節選項卡上
您可以使用FileVersionInfo類來獲得另一個程序的版本。
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\\Notepad.exe");
Console.WriteLine("File: " + myFileVersionInfo.FileDescription + '\n' +
"Version number: " + myFileVersionInfo.FileVersion);
如果我沒有錯,您試圖使用c#獲取文件的版本號。你可以試試下面的例子:
using System;
using System.IO;
using System.Diagnostics;
class Class1
{
public static void Main(string[] args)
{
// Get the file version for the notepad.
// Use either of the two following commands.
FileVersionInfo.GetVersionInfo(Path.Combine(Environment.SystemDirectory, "Notepad.exe"));
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\\Notepad.exe");
// Print the file name and version number.
Console.WriteLine("File: " + myFileVersionInfo.FileDescription + '\n' +
"Version number: " + myFileVersionInfo.FileVersion);
}
}
來源:http://msdn.microsoft.com/en-us/library/system.diagnostics.fileversioninfo(v=vs.110).aspx
@Ani我其實沒有特別請求版本信息,而是訪問出現在細節選項卡中的所有屬性。版本信息只是我需要訪問的一個例子。 – BenM
您可以嘗試探索File,FileInfo和FileVersionInfo類以獲取所需的詳細信息。 –
@AshishCharan這是正確的答案。我一直在尋找的那個。請隨意將此放在下面,我會接受它。 – BenM