为什么使用WMI时Win32_Product.InstallDate2总是返回null? [英] Why does Win32_Product.InstallDate2 always return null when using WMI?

查看:70
本文介绍了为什么使用WMI时Win32_Product.InstallDate2总是返回null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


更新:如果要在您的语言环境中快速进行测试启动PowerShell 按住Windows键,点击R,释放Windows键,键入 powershell,然后按OK ),然后运行
命令
-( InstallDate2列是否为空?请让我们知道您看到的内容。):

UPDATE: If you want to help test this quickly in your locale. Launch PowerShell (hold down the Windows key, tap R, release the Windows key, type in "powershell" and press OK) and run this command - (is the InstallDate2 column empty? Please let us know what you see.):



Get-WmiObject Win32_Product | Format-Table -Property InstallDate, InstallDate2, Name






首先,我要说的是,这个问题对我来说并不重要,但我感到困惑。我正在访问WMI对象 Win32_Product ,并且有两个与日期相关的属性:分别为 InstallDate InstallDate2


I should start by saying that this issue is not critical for me (yet), but I am baffled. I am accessing the WMI object Win32_Product, and there are two properties related to dates: InstallDate and InstallDate2 respectively.


  • InstallDate 似乎是DateTime值的字符串表示形式,没有时间部分。截断UTC格式。例如: 20170819 。该字段是一个字符串值,并且不是DateTime格式

  • InstallDate2 应该是真实的DateTime格式,但是它是对于我所有系统(Windows 7,Windows 10,各种版本)上的所有Win32_Product项始终为null。

  • InstallDate seems to be a string representation of a DateTime value without the time part. Sort of a cut-off UTC format. Example: 20170819. The field is a string value, and not a DateTime format.
  • InstallDate2 is supposed to be in real DateTime format, but it is consistently null for all Win32_Product items on all my systems (Windows 7, Windows 10, various editions).

使用 WMIExplorer .exe ,我看到InstallDate的描述: ...不赞成使用InstallDate2属性,而应使用DateDate类型而不是String类型的InstallDate2属性。新的实现应使用InstallDate2属性。 / em>

Using WMIExplorer.exe I see this description of InstallDate: "...the InstallDate property has been deprecated in favor of the InstallDate2 property which is of type DateTime rather than String. New implementations should use the InstallDate2 property."

如前所述,我在所有机器上都返回null,因此我假设InstallDate2根本没有正确实现,但随后我发现了这篇文章: a href = https://docs.microsoft.com/zh-cn/powershell/scripting/getting-started/cookbooks/working-with-software-installations?view=powershell-5.1 rel = nofollow noreferrer>工作软件安装。本文清楚地显示了InstallDate2返回WMI日期时间(缺少时间部分?): InstallDate2 = 20060506000000.000000-000

As stated I get null back on all my machines, so I was assuming that InstallDate2 was simply not implemented properly, but then I found this article: Working with Software Installations. This article clearly shows InstallDate2 returning a WMI DateTime (with missing time part?): InstallDate2 = 20060506000000.000000-000.

我只是想知道什么原因会导致在我的所有系统上这个InstallDate2空值出现在其他系统上吗?一些可能的想法让我望而却步(一个比另一个可能牵强得多) :

I am simply wondering what can be causing this InstallDate2 null value on all my systems when I see it working on other systems? Some possibilities that has crossed my mind (one more far fetched than the next perhaps):


  • 操作系统问题?我没有使用旧版操作系统的权限,但是在Windows 7和Windows 10系统的多个不同版本(家用版,终极版等)上看到null。也许它适用于XP及更高版本?我觉得这不太可能。

  • 区域设置问题?我在挪威语言环境中。这会影响事情吗?我曾尝试过在Windows 10系统上更改语言环境,但是它存在一些语言包问题,结果是相同的。

  • 域(网络)问题 ?可以想象工作组中的计算机与域中的计算机工作方式不同吗?

  • 补丁程序级别?最新的Windows Update是否可以更改WMI中的某些内容?

  • 还有什么可能会影响到此?

  • OS issue? I don't have access to older OSs, but I see null on several different editions (home, ulitmate, etc...) of Windows 7 and Windows 10 systems. Perhaps it worked on XP and older? I find this unlikely.
  • Locale issue? I am in a Norwegian locale. Could this affect things? I tried briefly to change the locale on a Windows 10 system, but it had some language pack issues and the result was the same.
  • Domain (network) issue? Is it conceivable that machines in workgroups work differently than machines that are part of a domain?
  • Patch level? Could a recent Windows Update have changed something in WMI?
  • What else could conceivably affect this?

问题的第二部分(除了InstallDate2空值的原因是什么)。我为InstallDate返回的字符串(字符串格式日期): 20170819 。我假设这只是通用时间坐标(UTC)格式。并且它是与语言环境无关的格式吗?当我阅读有关 CIM_DATETIME a>。

And a second part of the question (in addition to what the cause of the null value for InstallDate2 is). The string I get back for InstallDate (the string format date): 20170819. I am assuming this is just a chopped of version of Universal Time Coordinate (UTC) format. And that it is a locale-independent format? It seems like it when I read about CIM_DATETIME.

我尝试用零填充剩余的截止日期字符串,并将其传递给 SWbemDateTime脚本对象,它似乎可以正常工作,但实际上确实是一种解决方案。似乎一点也不可靠:

I tried filling the rest of the chopped off date string with zeros and passing it to a SWbemDateTime scripting object, and it seemed to work, but that really smells as a "solution". Doesn't seem reliable at all:

Set dateTime = CreateObject("WbemScripting.SWbemDateTime")
dateTime.Value = "20170601000000.000000+000"
MsgBox dateTime.Year
MsgBox dateTime.UTC

显示年份为2017,UTC为0。有了这样的解决方案,我显然真的很想让InstallDate2 DateTime字段正常工作,所以我可以获得正确的Datetime。

It shows 2017 for year, and 0 for UTC. With such a "solution" I obviously really want to get the InstallDate2 DateTime field working correctly so I get a proper Datetime back.

因此,就其所有的冗长而言,基本上是一个分为两个部分的问题:

So in all its verbosity, basically a two-part question:


  1. 可能是什么引起了 Win32_Product.InstallDate2 似乎只在我的系统上一致报告空

  2. InstallDate 返回的短字符串- 与语言环境无关的格式吗?


    • 由于我在挪威语言环境中,看似英语样式的格式,似乎是吗? 由于该字段只是一个字符串,所以内容基本上可以是任何内容。

    • 如果另一个语言环境中的人可以验证格式,那就太好了返回为: Win32_Product.InstallDate = yyyymmdd

    • 阅读 CIM_DATETIME 似乎表明该字符串与语言环境无关(即使已被砍掉)。

  1. What could be causing Win32_Product.InstallDate2 to consistently report null seemingly only on my systems?
  2. The short string returned by InstallDate - is this in a locale-independent format?
    • Since I am in a Norwegian locale and see what looks like an English style format, it would seem that it is? Since the field is just a string, the content could basically be "anything" though.
    • It would be great if someone in another locale could verify that the format returns as: Win32_Product.InstallDate = yyyymmdd.
    • Reading about CIM_DATETIME seems to indicate the string is locale-independent (even if chopped off).

如果要测试,最快的方法可能是使用 wbemtest。 exe (如果您的设备上有可用的话,还是更好的PowerShell-如JosefZ在下面的评论中所述):

If you want to test, the quickest way is probably using wbemtest.exe (or better yet PowerShell if you have it available on your box - as mentioned by JosefZ in the comment below):


  • 启动 wbemtest.exe 按住Windows键,点击R,释放Windows键,键入 wbemtest.exe,然后按OK )。

  • 单击连接 ,然后单击确定(名称空间默认为root\cimv2),然后单击 connect 。

  • 单击 查询,然后键入以下WQL命令: SELECT Name,InstallDate2 FROM Win32_Product ,然后单击使用(或等效按钮)。

  • 双击返回的任何条目,然后在中间的列表框中选中InstallDate2(向下滚动)。
  • li>
  • Launch wbemtest.exe (Hold down the Windows key, tap R, release the Windows key, type in "wbemtest.exe" and press OK).
  • Click "connect" and then OK (namespace defaults to root\cimv2), and click "connect" again.
  • Click "Query" and type in this WQL command: SELECT Name,InstallDate2 FROM Win32_Product and click "Use" (or equivalent).
  • Double click any entry returned, and check InstallDate2 in the middle list box (scroll down).

推荐答案

我认为您不会获得完整的日期时间。有效的唯一信息是有效地从MsiGetProductInfo(... INSTALLPROPERTY_INSTALLDATE ....)。此格式为YYYYMMDD。您将永远只获得数据,因为这一切似乎已经存在。请注意,INSTALLPROPERTY_INSTALLDATE的文档说,自安装产品以来没有其他服务,它是安装日期。因此,您似乎甚至不能依靠它作为产品的安装日期。

In my opinion you won't get a full date-time back. The only information available is effectively from MsiGetProductInfo (...INSTALLPROPERTY_INSTALLDATE....). This format is YYYYMMDD. You're only ever going to get the data because that seems to all there is. Note that the documentation for INSTALLPROPERTY_INSTALLDATE says that it is the installation date only if there has been no other servicing since the product was installed, so it appears that you can't even rely on it being the date the product was installed.

请参见检测程序的安装时间

我怀疑获取产品安装时间的最佳方法是使用MsiGetProductInfo获取本地软件包路径(例如)... INSTALLPROPERTY_LOCALPACKAGE ...并获取缓存的MSI的CreationDate。

I suspect the best way to get the time the product was installed is to get the local package path with MsiGetProductInfo (Ex) ...INSTALLPROPERTY_LOCALPACKAGE... and get the cached MSI's CreationDate.

这篇关于为什么使用WMI时Win32_Product.InstallDate2总是返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆