String comparison
I have connected to ROOT\\CIMV2 WMI namespace and after connecting run the following code.
1 2 3 4 5 6 7
|
IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("Select * from Win32_Process"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
|
After this I used while (pEnumerator) to get the name of each of the running processes.
I want to get the process id for just the explorer process but I can not get the string comparison to work.
I have tried the following:
1 2 3 4 5 6 7 8 9
|
VARIANT vtProp;
// Get the value of the Name property
hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
string procToFind = "explorer.exe";
string currentProc = (char *)vtProp.bstrVal;
wcout << vtProp.bstrVal << " = " << procToFind.c_str() << " " << procToFind.compare(currentProc) << endl;
|
The prints out "explorer.exe = explorer.exe 1".
Why are these two not equal? I am new to C and am confused by all the different types of strings.
The code I used to query the WMI came from
http://msdn.microsoft.com/en-us/library/aa390422%28VS.85%29.aspx
The only modification is the query I ran. Thanks for your help
Are you mixing Unicode and ASCII strings?
Topic archived. No new replies allowed.