为什么System.Diagnostics.FileVersionInfo.GetVersionInfo()会返回意外的文件版本信息?我正在查找有关MPIO驱动程序的版本信息。目标操作系统是Server2008R2 SP1,它应该返回FileVersion 6.1.7601。取而代之的是,我得到了6.1.7600的2008R2 RTM版本。
除了不正确的文件版本之外,OriginalFilename也不是我期望的那样。虽然FileName是正确的,但它是mpio.sys.mui。
使用资源管理器检查文件属性时,会显示正确的版本信息。
这是一个设计上的错误,还是我使用FileVersionInfo错误的一种方式?有没有什么变通办法,最好是在Powershell上?
$mpioPath = 'c:\windows\system32\drivers\mpio.sys'
$v = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($mpioPath)
$v | fl -Property *
Comments :
CompanyName : Microsoft Corporation
FileBuildPart : 7601
FileDescription : MultiPath Support Bus-Driver
FileMajorPart : 6
FileMinorPart : 1
FileName : c:\windows\system32\drivers\mpio.sys
FilePrivatePart : 17619
FileVersion : 6.1.7600.16385 (win7_rtm.090713-1255)
InternalName : mpio.sys
IsDebug : False
IsPatched : False
IsPrivateBuild : False
IsPreRelease : False
IsSpecialBuild : False
Language : English (United States)
LegalCopyright : © Microsoft Corporation. All rights reserved.
LegalTrademarks :
OriginalFilename : mpio.sys.mui
PrivateBuild :
ProductBuildPart : 7601
ProductMajorPart : 6
ProductMinorPart : 1
ProductName : Microsoft® Windows® Operating System
ProductPrivatePart : 17619
ProductVersion : 6.1.7600.16385
SpecialBuild :使用C#程序也可以得到同样的结果,所以这似乎更像是.Net的特性,而不是Powershell特有的特性。
namespace Foo {
class GetFileVersionInfo {
static void Main(string[] args) {
string mpio = @"c:\windows\system32\drivers\mpio.sys";
System.Diagnostics.FileVersionInfo fvInfo;
fvInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(mpio);
System.Console.WriteLine("Original file name: " + fvInfo.OriginalFilename);
System.Console.WriteLine("FileVersion: " + fvInfo.FileVersion);
}
}
}使用FileVer.exe返回正确的版本信息:
filever $mpioPath
--a-- W32 DRV ENU 6.1.7601.17619 shp 156,544 05-20-2011 mpio.sys如果其他方法都不起作用,我可以使用FileVer并解析它的输出。
发布于 2013-01-25 22:01:31
我猜FileVer.exe和expolrer.exe做的事情和你在powershell中做的一样:
$mpioPath = 'c:\windows\system32\drivers\mpio.sys'
$v = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($mpioPath)
$ver = "{0}.{1}.{2}.{3}" -f $v.FileMajorPart, $v.FileMinorPart, $v.FileBuildPart, $v.FilePrivatePart发布于 2014-02-28 19:42:53
在MSDN page for GetFileVersionInfo上,它说:
文件版本信息分为固定部分和非固定部分。固定部分包含版本号等信息。非固定部分包含字符串之类的内容。在过去,GetFileVersionInfo从二进制文件(exe/dll)中获取版本信息。目前正在从语言中性文件(exe/dll)中查询固定版本,从mui文件中查询非固定部分,合并后返回给用户。
这与您看到的完全一致:一个版本号来自c:\windows\system32\drivers\mpio.sys,另一个来自c:\windows\system32\drivers\[your language]\mpio.sys.mui
发布于 2013-12-23 03:50:00
据我所知,字段"FileVersion“和"ProductVersion”是unicode 字符串。相比之下,字段"FileMajorPart“、"FileMinorPart”、"FileBuildPart“和"FilePrivatePart”是DWORD值。字段"ProductMajorPart“、"ProductMinorPart”、"ProductBuildPart“和"ProductPrivatePart”也是DWORD值:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646997%28v=vs.85%29.aspx
用于创建VersionBlock的应用程序可能允许字符串和DWORD域之间的不一致。例如,某些版本的Visual Studio将始终更新DWORD字段以反映对字符串所做的更改。但是,仅对DWORD值的更新不会反映在字符串中。因此,根据用于编码的应用程序的不同,可能会出现不同程度的不一致。根据我的经验,仅使用DWORD字段将获得最佳结果(正如在回答您的问题时所建议的那样)。
https://stackoverflow.com/questions/14522497
复制相似问题