【问题标题】:Powershell get-item VersionInfo.ProductVersion incorrect / different than WMIPowershell get-item VersionInfo.ProductVersion 不正确/不同于 WMI
【发布时间】:2012-06-18 20:55:51
【问题描述】:

我试图理解为什么 Powershell 会为 DLL 文件返回一个与 Windows 资源管理器中的文件属性页面和 WMI 查询显示的版本号不同的版本号。 (如果这不符合编码问题的要求,我提前道歉。)

场景:

运行以下 powershell 命令:

(get-item C:\windows\system32\rdpcorekmts.dll).VersionInfo.ProductVersion

这将返回以下内容:

6.1.7600.16385

但是,此版本号不正确。从 Windows 资源管理器检查版本信息时,您会看到以下版本(抱歉,我尝试发布它的小屏幕截图,但我没有足够的代表;我是新来的):

6.1.7601.17767

此外,WMIC 查询显示的结果与 Windows 资源管理器相同:

WMIC path CIM_DataFile WHERE (name="c:\\windows\\system32\\rdpcorekmts.dll") get Version

WMIC 结果:

版本

6.1.7601.17767

我真的不明白为什么它们会有所不同。我真的很想使用 Powershell 返回这个值,但现在我不确定我是否只是忽略了某些东西,或者我是否遇到了某种奇怪的错误,但是这两种方法之间的版本不匹配令人困惑。需要说明的是,我已经对在 Powershell 中恢复它的方法进行了变体(例如 Get-ItemChild 和 Get-ItemProperty),但我得到了相同的错误版本结果。

有什么想法吗?

【问题讨论】:

  • 可以获得的版本非常多(Assembly Version, File Version, Product Version)。您确定差异是针对同一属性吗?

标签: powershell wmi-query wmic versioninfo


【解决方案1】:

问题是您正在使用ProductVersion 属性,它似乎在某处被硬编码,IE 和 WMI 只是从以下产品版本中构建的:

ProductMajorPart   : 6
ProductMinorPart   : 1
ProductBuildPart   : 7601
ProductPrivatePart : 17767

FileVersion 相同:FileMajorPart、FileMinorPart、FileBuildPart、FilePrivatePart

试试看:

(get-item C:\windows\system32\rdpcorekmts.dll).VersionInfo | fl *

你可以测试一下:

(get-item C:\windows\system32\rdpcorekmts.dll).VersionInfo | % {("{0}.{1}.{2}.{3}" -f $_.ProductMajorPart,$_.ProductMinorPart,$_.ProductBuildPart,$_.ProductPrivatePart)}

从 CMD.EXE 你可以试试:

C:\>powershell -command "&{(get-item C:\windows\system32\rdpcorekmts.dll).VersionInfo | % {write-host ('{0}.{1}.{2}.{3}' -f $_.ProductMajorPart,$_.ProductMinorPart,$_.ProductBuildPart,$_.ProductPrivatePart)}}"

【讨论】:

  • 您的解决方案效果很好——非常感谢。感谢您花时间如此彻底地解释答案。非常感谢!
  • 还有一个问题:有没有办法通过 Windows cmd 行来完成这项工作?例如powershell -Command "& (get-item C:\windows\system32\rdpcorekmts.dll).VersionInfo | % {("{0}.{1}.{2}.{3}" -f $_.ProductMajorPart, $_.ProductMinorPart,$_.ProductBuildPart,$_.ProductPrivatePart)}"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-15
  • 2015-01-18
  • 2015-02-07
相关资源
最近更新 更多