Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WMI Connect Crash in static program *** 25 EURO Voucher for BugFix ***

79 views
Skip to first unread message

mansc...@googlemail.com

unread,
Jun 16, 2013, 5:27:33 AM6/16/13
to
hello there,

i am having some issues with WMI Code .. its crashing sometimes (most of the time its not) and i just cant find the reason for that.

If anybody got a guess, what it might be, i'd be very happy to know.

I'm having a multi-project setup in MSVS 2010 with static program compilation (static pthread for example)... Stack Trace is:

KernelBase.dll!_QueryRegValue@24() + 0xe9 Bytes
KernelBase.dll!_ValidateLocaleRegistryKey@12() + 0x3f Bytes
KernelBase.dll!_MakeNamedLocaleHashNode@8() + 0xa7 Bytes
KernelBase.dll!@GetNamedLocaleHashNode@8() + 0x56 Bytes
KernelBase.dll!_NlsValidateNamedLocale@4() + 0xf Bytes
KernelBase.dll!_LocaleNameToLCID@8() + 0x17 Bytes
wbemcomn.dll!CMUILocale::_LocaleNameToLCID() + 0x2a Bytes
wbemcomn.dll!CMUILocale::LocaleName_To_LCID() + 0x2c Bytes
wbemcomn.dll!CMUILocale::GetPreferredLanguages() - 0x75 Bytes
wbemprox.dll!CDCOMTrans::DoActualConnection() + 0x30c Bytes
wbemprox.dll!CDCOMTrans::DoConnection() + 0x27 Bytes
wbemprox.dll!CLocator::ConnectServer() + 0x79 Bytes
> meine.exe!Engine::calcMainboardID() Zeile 166 + 0x27 Bytes C++
meine.exe!Engine::Engine() Zeile 37 + 0xf Bytes C++
meine.exe!Engine::getInstance() Zeile 40 + 0x22 Bytes C++
meine.exe!MeineApplication::MeineApplication(int argc=1, char * * argv=0x002a2178) Zeile 22 + 0x9 Bytes C++
meine.exe!main(int argc=1, char * * argv=0x002a2178) Zeile 53 + 0x10 Bytes C++
meine.exe!__tmainCRTStartup() Zeile 278 + 0x19 Bytes C
meine.exe!mainCRTStartup() Zeile 189 C
kernel32.dll!@BaseThreadInitThunk@12() + 0x12 Bytes
ntdll.dll!___RtlUserThreadStart@8() + 0x27 Bytes
ntdll.dll!__RtlUserThreadStart@8() + 0x1b Bytes

Error Msg is:

Eine Ausnahme (erste Chance) bei 0x75035d7e (KernelBase.dll) in meine.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x00b1f02e.
Unbehandelte Ausnahme bei 0x75035d7e (KernelBase.dll) in meine.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0x00b1f02e.

The Code is kinda from Microsoft Example about WMI:

HRESULT hres;

// Initialize COM.
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
//hres = CoInitialize(0);
if (FAILED(hres)) {
std::cout << "Failed to initialize COM library. "
<< "Error code = 0x"
<< hex << hres << endl;
//return std::string("fail1"); // Program has failed.
}

// Initialize
hres = CoInitializeSecurity(
NULL,
-1, // COM negotiates service
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
);


if (FAILED(hres)) {
std::cout << "Failed to initialize security. "
<< "Error code = 0x"
<< hex << hres << endl;
// CoUninitialize();
return std::string("fail2"); // Program has failed.
}

// Obtain the initial locator to Windows Management on a particular host computer.
IWbemLocator *pLoc = 0;

hres = CoCreateInstance(
CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLoc);

if (FAILED(hres) || !pLoc) {
std::cout << "Failed to create IWbemLocator object. "
<< "Error code = 0x"
<< hex << hres << endl;
// CoUninitialize();
return std::string("fail3"); // Program has failed.
}
IWbemServices *pSvc = 0;

std::cout << "before var \n";

_bstr_t testVar = _bstr_t("ROOT\\CIMV2");

std::cout << "before connect \n";


qDebug() << "ploc is: " << pLoc << "::" << endl;

// Connect to the root\cimv2 namespace with the current user and obtain pointer pSvc to make IWbemServices calls
hres = pLoc->ConnectServer(
testVar, // WMI namespace
NULL, // User name
NULL, // User password
0, // Locale
NULL, // Security flags
0, // Authority
0, // Context object
&pSvc // IWbemServices proxy
);

///////// TODO: Hier ist Crash /////////////
std::cout << "after connect \n";

if (FAILED(hres)) {
std::cout << "Could not connect. Error code = 0x"
<< hex << hres << endl;
pLoc->Release();
// CoUninitialize();
return std::string("fail4"); // Program has failed.
}
std::cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl;

// Set the IWbemServices proxy so that impersonation of the user (client) occurs.
hres = CoSetProxyBlanket(
pSvc, // the proxy to set
RPC_C_AUTHN_WINNT, // authentication service
RPC_C_AUTHZ_NONE, // authorization service
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_CALL, // authentication level
RPC_C_IMP_LEVEL_IMPERSONATE, // impersonation level
NULL, // client identity
EOAC_NONE // proxy capabilities
);

if (FAILED(hres)) {
cout << "Could not set proxy blanket. Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
// CoUninitialize();
return std::string("fail5"); // Program has failed.
}

// Use the IWbemServices pointer to make requests of WMI. Make requests here:

std::cout << "before query \n";

// For example, query for all the running processes
IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_BaseBoard"), //Win32_Process"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);

if (FAILED(hres)) {
cout << "Query for processes failed. "
<< "Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
// CoUninitialize();
return std::string("fail6"); // Program has failed.

} else {
IWbemClassObject *pclsObj;
ULONG uReturn = 0;

std::cout << "debug 122 \n";

while (pEnumerator) {

std::cout << "DEBUG 123\n";

hres = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);

if(0 == uReturn) {
break;
}

VARIANT vtProp;

// Get the value of the SerialNumber property
hres = pclsObj->Get(L"SerialNumber"/*"Name"*/, 0, &vtProp, 0, 0);
//wcout << "Process Name : " << vtProp.bstrVal << endl;


std::cout << "before copyString \n";

// Convert output to std::string
std::wstring outputW(vtProp.bstrVal, SysStringLen(vtProp.bstrVal));
std::string output(outputW.begin(), outputW.end());

VariantClear(&vtProp);
return output;
}

}

// Cleanup
// ========
/*pSvc->Release();
pLoc->Release();
CoUninitialize();
*/
return std::string("fail77");

Note, that I have commented out the release things temporarily to ensure thats these are not the issues.. The Error still popsup however.

I am willing to grant a 25 EURO Voucher for anybody who can fix the problem (first one only gets it. Posted in several forums.) Vouchers can be from like Amazon, IKEA or whatever else vouchers I can buy in germany.

Yours,
Manuel Schmidt
0 new messages