WMI使用WBEM_FLAG_FORWARD_ONLY标志调用C# [英] WMI Calls in C# with WBEM_FLAG_FORWARD_ONLY Flag
问题描述
使用System.Management;
ManagementObjectSearcher searcher = new ManagementObjectSearcher(" SELECT UserName FROM
Win32_ComputerSystem");
              if(searcher!= null)
              {
                    ManagementObjectCollection
collection = searcher.Get();
}
要释放COM对象。请帮助我们如何在C#中添加Flags或建议任何其他方法
来执行WMI查询。
推荐答案
考虑$的构造函数b $ b ManagementObjectSearcher ,它接受 EnumerationOptions 对象。将 EnumerationOptions 的
可重绕参数的值设置为 false :
https:// docs。 microsoft.com/en-us/dotnet/api/system.management.managementobjectsearcher.-ctor?view=netframework-4.7.2#System_Management_ManagementObjectSearcher__ctor_System_String_System_String_System_Management_EnumerationOptions _ 跨度> 跨度> 跨度> 跨度>
Consider the constructors of ManagementObjectSearcher that takes an EnumerationOptions object. Set the value of rewindable parameter of EnumerationOptions to false: https://docs.microsoft.com/en-us/dotnet/api/system.management.managementobjectsearcher.-ctor?view=netframework-4.7.2#System_Management_ManagementObjectSearcher__ctor_System_String_System_String_System_Management_EnumerationOptions_
这篇关于WMI使用WBEM_FLAG_FORWARD_ONLY标志调用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!