我们拥有包含自定义版本信息的大型可执行文件(> 1,2 GB)。 我试图通过使用'FileVersionInfo'类的'GetVersionInfo'从这些文件中检索'版本信息'。 由于某些原因,此方法在Windows XP中不会返回较大文件的版本信息(使用> 1 GB进行测试)。它的确适用于大小为18 MB的文件。 当我在Windows 7(x86和X64)中尝试使用它时,它适用于所有文件,即使是更大的使用者!从大文件中检索版本信息
我用了一个反射器工具来看看进入FileVersionInfo类和我创建了一个小型控制台应用检索“文件版本Info'尺寸, 就像‘GetVersionInfo’的方法一样。在Windows XP中返回0(零)的大小,在Windows 7中返回相同文件的大小为1428的大小。 XP中的最后一个错误是1812('指定的图像文件不包含资源部分')。
为什么这在Windows XP中不起作用,并在Windows 7中起作用的原因是什么? 是否有解决方法来检索版本信息?
下面的代码我已经测试:
class Program
{
[DllImport("version.dll", BestFitMapping = false, CharSet = CharSet.Auto, SetLastError = true)]
public static extern int GetFileVersionInfoSize(string lptstrFilename, out int handle);
static void Main(string[] args)
{
Console.Write("Path which contains the executables: ");
string path = Console.ReadLine();
foreach (string fileName in Directory.EnumerateFiles(path))
{
int num;
int fileVersionInfoSize = GetFileVersionInfoSize(fileName, out num);
int error = Marshal.GetLastWin32Error();
Console.WriteLine("File Version Info Size: " + fileVersionInfoSize);
if (error != 0)
{
Console.WriteLine("Last Error: " + error);
}
}
Console.ReadKey();
}
}
要确认,18MB文件在XP上工作? – keyboardP 2012-01-11 15:50:11
是的,18 MB在XP上工作! – RBDev 2012-01-11 15:50:49