如何获取 ManagementObjects 的计数(WMI 结果)而不通过 .NET 中的集合进行枚举

发布于 2024-08-30 02:22:40 字数 301 浏览 2 评论 0原文

当通过 WMI 查询大量数据时(例如 Windows 事件日志 Win32_NTLogEvent),在下载所有内容之前了解您正在获取的数据类型非常有用。有办法两个人做到这一点吗?

据我所知,WQL 中没有“Select Count(*) FROM Win32_NTLogEvent”。

据我所知,无论将 Rewindable 属性设置为 true 还是 false, ManagementObjectCollection 的 Count 属性实际上都会枚举所有结果。

如果在.NET中无法完成,是否可以直接使用底层IWbem对象来完成 谢谢

When querying for large ammount of data through WMI (say the windows events log Win32_NTLogEvent) it is very useful to know what kind of numbers you are getting yourself into before downloading all the content. Is there a way two do this?

From what i know there is no "Select Count(*) FROM Win32_NTLogEvent" in WQL.

From what i know the Count property of the ManagementObjectCollection actually enumerates through all the results whether you have the Rewindable property set to true or false.

If it cannot be done in .NET, can it be done by directly using the underlying IWbem objects
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老娘不死你永远是小三 2024-09-06 02:22:40

底层 IWbem 对象还返回一个枚举。
例如 IWbemServices::ExecQuery 方法返回 IEnumWbemClassObject

但是,请参阅 < a href="http://msdn.microsoft.com/en-us/library/aa390880(v=VS.85).aspx" rel="nofollow noreferrer">提高枚举性能的一些想法.
值得注意的是,WBEM_FLAG_FORWARD_ONLY
如果您使用 C#,我猜它会调用 ManagementObjectSearcherEnumerationOptions.Rewindable 设置为 false。默认情况下,可回卷是正确的,因此关闭它应该会带来一些改进。

(如果您只在查询中请求一个(关键)属性,您还可以分析一下是否有任何性能改进。例如,Select RecordNumber FROM Win32_NTLogEvent 而不是 Select * FROM Win32_NTLogEvent.
理论上不需要实例化那么多信息,尽管实际上它仍然必须枚举所有内容,而且我不记得是否从中看到了任何改进。不过,值得检查一下时间。)

The underlying IWbem objects also return an enumeration.
E.g. The IWbemServices::ExecQuery Method returns an IEnumWbemClassObject

However, see Improving Enumeration Performance for a couple of ideas.
Notably, the WBEM_FLAG_FORWARD_ONLY.
If you're in C# I'm guessing it would be calling ManagementObjectSearcher with EnumerationOptions.Rewindable set to false. Rewindable is true by default, so turning it off should give some improvement.

(You could also profile to see if there's any performance improvement if you just ask for one (key) property in your query. E.g. Select RecordNumber FROM Win32_NTLogEvent instead of Select * FROM Win32_NTLogEvent.
In theory not as much info would need to be instantiated, though in realityit still has to enumerate everything, and I don't remember if I ever saw any improvement from that. Worth a timing check, though.)

回忆那么伤 2024-09-06 02:22:40

看来是做不到了。下一个最好的事情是达林上面提供的答案。

It appears that it cannot be done. The next best thing is the answer provided above by Daryn.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文