问题描述
在调用WMI的 searcher.Get()方法时抛出异常,是什么原因?
以下异常堆栈
消息:
指定的演员表无效。
StackTrace:
在System.StubHelpers.InterfaceMarshaler.ConvertToNative(Object objSrc,IntPtr itfMT,IntPtr classMT,Int32 flags)
at System.Management.SecuredIWbemServicesHandler.ExecQuery_(String strQueryLanguage,String strQuery,Int32 lFlags,IWbemContext pCtx,IEnumWbemClassObject& ppEnum)
在System.Management.ManagementObjectSearcher.Get()
以下代码
var searcher = new ManagementObjectSearcher(@" root \\ \\ cimv2",
" SELECT * FROM Win32_DiskDrive");
foreach(searcher.Get()中的ManagementObject项目)
{
//列表项目代码
}
Hi,
throw exception when call the WMI's searcher.Get() method , what's reason?
following exception stack
Message:
Specified cast is not valid.
StackTrace:
at System.StubHelpers.InterfaceMarshaler.ConvertToNative(Object objSrc, IntPtr itfMT, IntPtr classMT, Int32 flags)
at System.Management.SecuredIWbemServicesHandler.ExecQuery_(String strQueryLanguage, String strQuery, Int32 lFlags, IWbemContext pCtx, IEnumWbemClassObject& ppEnum)
at System.Management.ManagementObjectSearcher.Get()
following code
var searcher = new ManagementObjectSearcher(@"root\cimv2", "SELECT * FROM Win32_DiskDrive"); foreach (ManagementObject item in searcher.Get()) { //list item code }
这篇关于WPF应用程序调用WMI API抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!