Click here to Skip to main content
15,917,709 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Connecting to WMI -using COM Pin
Member 432083116-Jul-09 1:59
Member 432083116-Jul-09 1:59 
Well I've initialized it as COINIT_MULTITHREADED in CoInitializeEx() but it doesn't work as hoped. I use the same IWbemServices pointer (all initializations done just the first time) to run an ExecNotificationQuery with different WMI queries. However my ExecNotificationQuery fails. The two queries work fine if done individually but I can't seem to be able register for two separate WMI events separately.

If I do the whole initialization again for my 2nd query then I get an error in COM security initialization.

Code Snippet:
HANDLE hres;
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres))
{output something}
hres = CoInitializeSecurity(NULL,1,NULL,NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE,NULL, EOAC_NONE,NULL);
hres = CoCreateInstance(
CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLoc);
hres = pLoc->ConnectServer(
_bstr_t(L"ROOT\\WMI"), // Object path of WMI namespace
NULL, // User name. NULL = current user
NULL, // User password. NULL = current
0, // Locale. NULL indicates current
NULL, // Security flags.
0, // Authority (e.g. Kerberos)
0, // Context object
&pSvc // pointer to IWbemServices proxy
);
hres = CoSetProxyBlanket(
pSvc, // Indicates the proxy to set
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
NULL, // client identity
EOAC_NONE // proxy capabilities
);

IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecNotificationQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM ..."),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
Then I use pEnumerator->Next within a loop and cleanup.

I run this function twice in separate threads.Ideas?
QuestionIP from socket handle Pin
sunny_vc15-Jul-09 21:17
sunny_vc15-Jul-09 21:17 
AnswerRe: IP from socket handle Pin
CPallini15-Jul-09 21:28
mveCPallini15-Jul-09 21:28 
QuestionCreateProcess doesn’t passes command line arguments [modified] Pin
staticv15-Jul-09 20:56
staticv15-Jul-09 20:56 
AnswerRe: CreateProcess doesn’t passes command line arguments Pin
Franck Paquier15-Jul-09 21:18
Franck Paquier15-Jul-09 21:18 
AnswerRe: CreateProcess doesn’t passes command line arguments Pin
Michael Schubert15-Jul-09 22:17
Michael Schubert15-Jul-09 22:17 
AnswerRe: CreateProcess doesn’t passes command line arguments Pin
Stuart Dootson15-Jul-09 22:20
professionalStuart Dootson15-Jul-09 22:20 
AnswerRe: CreateProcess doesn’t passes command line arguments Pin
tns_ranjith15-Jul-09 22:41
tns_ranjith15-Jul-09 22:41 
GeneralRe: CreateProcess doesn’t passes command line arguments Pin
Michael Schubert15-Jul-09 23:00
Michael Schubert15-Jul-09 23:00 
GeneralRe: CreateProcess doesn’t passes command line arguments Pin
Rajesh R Subramanian15-Jul-09 23:45
professionalRajesh R Subramanian15-Jul-09 23:45 
GeneralRe: CreateProcess doesn’t passes command line arguments Pin
Michael Schubert15-Jul-09 23:48
Michael Schubert15-Jul-09 23:48 
GeneralRe: CreateProcess doesn’t passes command line arguments Pin
tns_ranjith16-Jul-09 0:11
tns_ranjith16-Jul-09 0:11 
QuestionHow to test is the given path is a directory or a file? Pin
Chesnokov Yuriy15-Jul-09 20:56
professionalChesnokov Yuriy15-Jul-09 20:56 
AnswerRe: How to test is the given path is a directory or a file? Pin
Randor 15-Jul-09 21:08
professional Randor 15-Jul-09 21:08 
AnswerRe: How to test is the given path is a directory or a file? Pin
Chesnokov Yuriy15-Jul-09 22:50
professionalChesnokov Yuriy15-Jul-09 22:50 
AnswerRe: How to test is the given path is a directory or a file? [modified] Pin
CPallini15-Jul-09 21:21
mveCPallini15-Jul-09 21:21 
GeneralRe: How to test is the given path is a directory or a file? Pin
Randor 15-Jul-09 21:38
professional Randor 15-Jul-09 21:38 
GeneralRe: How to test is the given path is a directory or a file? Pin
CPallini15-Jul-09 21:43
mveCPallini15-Jul-09 21:43 
GeneralRe: How to test is the given path is a directory or a file? Pin
Michael Schubert15-Jul-09 23:13
Michael Schubert15-Jul-09 23:13 
AnswerRe: How to test is the given path is a directory or a file? Pin
Michael Schubert15-Jul-09 22:29
Michael Schubert15-Jul-09 22:29 
QuestionHelp in writing a program? Pin
jon ray15-Jul-09 20:50
jon ray15-Jul-09 20:50 
QuestionRe: Help in writing a program? Pin
David Crow16-Jul-09 2:52
David Crow16-Jul-09 2:52 
AnswerRe: Help in writing a program? Pin
jon ray24-Jul-09 18:45
jon ray24-Jul-09 18:45 
GeneralRe: Help in writing a program? Pin
David Crow27-Jul-09 3:19
David Crow27-Jul-09 3:19 
QuestionHow to use ACL to change the access of usb device Pin
Anil Veeraghattapu 415-Jul-09 20:04
Anil Veeraghattapu 415-Jul-09 20:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.