繁体   English   中英

如何读取zip存档中的.exe版本号?

[英]How do I read the version number of an .exe inside a zip archive?

我有一个包含exe的zip文件,我想获取exe文件的版本号,而不必实际提取它。

我知道如何读取zip文件的内容,并且具有在其中读取文本文件的代码,但是我无法找到如何获取exe版本。

添加对Shell32.dll -library的引用。 然后,您可能会找到您想要的东西:

 
 
 
  
   Shell shell = new Shell(); var folder = shell.NameSpace( <path_to_your_zip> ); // Just get the names of the properties List<string> arrHeaders = new List<string>(); for (int i = 0; i < short.MaxValue; i++) { string header = folder.GetDetailsOf(null, i); if (String.IsNullOrEmpty(header)) break; arrHeaders.Add(header); } // Loop all files inside the zip and output their properties to console foreach (Shell32.FolderItem2 item in folder.Items()) { for (int i = 0; i < arrHeaders.Count; i++) { Console.WriteLine("{0}\\t{1}: {2}", i, arrHeaders[i], folder.GetDetailsOf(item, i)); } }
 
  

编辑:似乎没有实际从包中提取文件是不可能的。 诸如此类的事情非常简单,但是如果文件很大和/或有效压缩,将花费一些时间。

Shell s = new Shell();
var folder = s.NameSpace( <path_to_your_zip> );

foreach (FolderItem2 item in folder.Items())
{
  string oItemName = Path.GetFileName(item.Path);

  try
  {

    string oTargetFile = Path.Combine(Path.GetTempPath(), oItemName);
    if (File.Exists(oTargetFile))
      File.Delete(oTargetFile);

    Folder target = s.NameSpace(Path.GetTempPath());
    target.CopyHere(item, 4);

    var info = FileVersionInfo.GetVersionInfo(oTargetFile);

    if (File.Exists(oTargetFile))
      File.Delete(oTargetFile);

    Console.WriteLine(oItemName + "'s version is: " + info.FileVersion);
  }
  catch (Exception e)
  { 
    Console.WriteLine(oItemName + ": Unable to obtain version info.\n" + e.Message);  
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM