WMI引发异常“0x800706B5:接口未知。” [英] WMI raises exception "0x800706B5: The interface is unknown."
问题描述
我有一段代码可以无缝地工作到现在为止。它使用Windows Management Instrumentation API。我没有更改我的机器中的代码或任何内容(据我所知),但现在当代码在Visual Studio调试器(2008或2003)下运行时,它会引发异常,显然是在调用<$ c $时c> ConnectServer 在下面的代码中:
I have a piece of code that worked seamlessly until now. It uses the Windows Management Instrumentation API. I have not changed the code nor anything in my machine (as far as I know), but now when the code is run under the Visual Studio debugger (either 2008 or 2003), it raises an exception, apparently when calling ConnectServer
in the code below:
HRESULT hRes;
// Initialize
CoInitialize(0);
// Create the locator
IWbemLocator* pIWbemLocator= NULL;
IWbemServices* pWbemServices= NULL;
hRes= CoCreateInstance(
CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pIWbemLocator);
if (hRes != S_OK)
{
return false; // Could not create the locator
}
// Connect to the server
hRes= pIWbemLocator->ConnectServer(
L"ROOT\\CIMV2", // WMI namespace
NULL, // User name
NULL, // User password
0, // Locale
NULL, // Security flags
0, // Authority
0, // Context object
&pWbemServices // IWbemServices proxy
);
if (hRes != S_OK)
{
return false; // Could not connect to the server
}
如果我忽略异常,则会得到0xC0020043:RPC中发生内部错误。例外。
我相信代码是正确的,因为它已经使用多年了。我强调,在没有调试器的情况下执行仍然有效(发布和调试版本),所以我不能责怪我的Windows配置。但是当我想调试时我就陷入困境。
有人可以帮忙吗?
If I Ignore the exception, I then get a "0xC0020043: An internal error occurred in RPC." exception.
I am confident that the code is correct as it has been in use for years. And I stress that when executing without the debugger is still works (both Release and Debug builds), so I cannot blame my Windows configuration. But I am stuck when I want to debug.
Can anybody help ?
推荐答案
这里有一个样品。
http:// msdn .microsoft.com / zh-CN / library / windows / desktop / aa390423(v = vs.85).aspx [ ^ ]
试着让它运行。
有趣的区别是:
here is a sample.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa390423(v=vs.85).aspx[^]
Try to get it running.
The interesting difference ist:
CoInitializeEx(0, COINIT_MULTITHREADED);
作为一个工作区,我已经针对这个特定的例外禁用了调试器的中断。
调试>例外......>添加> Win32异常>
输入无法找到界面和0x800706B5。然后取消选中例外。
似乎到目前为止工作,希望它在最不希望的时候不会重现......
As a workaroud, I have disabled the break into the debugger for this specific exception.
Debug > Exceptions... > Add > Win32 Exceptions >
enter "The interface can not be found" and "0x800706B5". Then uncheck the exception.
Seems to work so far, hoping it will not resurface when the least desired...
这篇关于WMI引发异常“0x800706B5:接口未知。”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!