Re: problem with IWbemService.ExecNotificationQuery()

From: Philip Nunn [MSFT] (pnunn_at_online.microsoft.com)
Date: 07/07/04


Date: Tue, 6 Jul 2004 17:26:48 -0700

It seems that ExecQuery (preferred) or ExecQueryAsync will suit your needs.
The ExecNotificationQuery calls are for obtaining real-time events such as
changes to data, actions, etc. Since you just want to obtain informational
objects and read the properties, the classes used are not event classes.

-- 
Philip Nunn [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights. 
Use of included script samples are subject to the terms specified at 
http://www.microsoft.com/info/cpyright.htm.
"rayudu_kamma" <rayudukamma@discussions.microsoft.com> wrote in message 
news:4A1A78A4-E898-41A5-B6EF-562E66BCFDDF@microsoft.com...
> Hi,
> Im trying to get the network interface details using WMI.
> I could get it if I use ExecQuery() but couldn't if I go for either sync. 
> Notification or Asyn.Notification query. As I've to collect the details 
> from all the systems in LAN I think Async.Notification could help me a 
> lot.
> I m giving my code part .
> Pls help me.
> Thank you very much.
> Regards,
> Rayudu.
>
>
>
> {
> HRESULT hr;
> hr=CoInitializeEx(NULL,COINIT_MULTITHREADED);//COINIT_APARTMENTTHREADED);//hr=CoInitialize(NULL);
> if(hr==S_OK)
> AfxMessageBox((CString)"sok");
> else {AfxMessageBox((CString)"faild in initializing the com");
> return false;
> }
> if(hr==S_FALSE)
> {
> AfxMessageBox((CString)"s false. ie already installed");
> }
> if(hr==RPC_E_CHANGED_MODE)
> {
> AfxMessageBox((CString)"changed mode. ie prev ex did it");
> }
> hr=CoInitializeSecurity(NULL,-1,NULL,NULL,RPC_C_AUTHN_LEVEL_NONE,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE,0);
> if(hr==S_OK)
> AfxMessageBox((CString)"Indicates success.");
> if(hr==RPC_E_TOO_LATE)
> AfxMessageBox((CString)"CoInitializeSecurity has already been called.");
> if(hr==RPC_E_NO_GOOD_SECURITY_PACKAGES)
> {
> AfxMessageBox((CString)"asAuthSvc was not NULL, and none of the 
> authentication services in the list could be registered. Check the results 
> saved in asAuthSvc for authentication service-specific error codes.");
> }
> IWbemLocator *iloc=NULL;
> IWbemServices *iserv=NULL;
> MULTI_QI mqi[1];
> memset(mqi,0,sizeof(MULTI_QI));
> COSERVERINFO serverinfo;
> memset(&serverinfo,0,sizeof(COSERVERINFO));
> serverinfo.pwszName=_bstr_t(details.server);
> mqi[0].hr=hr;
> mqi[0].pIID=&IID_IWbemLocator;
> mqi[0].pItf=iloc;
> hr=CoCreateInstanceEx(CLSID_WbemLocator,0,CLSCTX_INPROC_SERVER,&serverinfo,1,mqi);
> if(hr!=S_OK)
> return false;
> iloc=(IWbemLocator *)mqi[0].pItf;
> hr=iloc->ConnectServer(details.snamespace,details.user,details.pwd,NULL,0,NULL,NULL,&iserv);
> CString tstr="";
> if(hr==WBEM_E_ACCESS_DENIED) tstr="The current or specelse ified user name 
> and password were not valid or authorized to make the connection.";
> else if(hr==WBEM_E_FAILED) tstr="This indicates other unspecelse ified 
> errors. ";
> else if(hr==WBEM_E_INVALID_NAMESPACE) tstr="The specelse ified namespace 
> did not exist on the server.";
> else if(hr==WBEM_E_INVALID_PARAMETER) tstr="An invalid parameter was 
> specelse ified.";
> else if(hr==WBEM_E_OUT_OF_MEMORY) tstr="There was not enough memory to 
> complete the operation.";
> else if(hr==WBEM_E_TRANSPORT_FAILURE) tstr="This indicates the failure of 
> the remote procedure call (RPC) link between the current process and 
> Windows Management.";
> else if(hr==WBEM_E_LOCAL_CREDENTIALS) tstr="WMI is passing the user 
> credential on local connection.";
> else if(hr==WBEM_S_NO_ERROR) tstr="The call succeeded.";
> {
> tstr +="  :   this is abt connect server";
> AfxMessageBox(tstr);
> }
> HRESULT hrr;
> CString tmp="";
> hrr=CoSetProxyBlanket(iserv,RPC_C_AUTHN_WINNT,RPC_C_AUTHZ_NONE,NULL,RPC_C_AUTHN_LEVEL_DEFAULT,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE);
> if(hrr==S_OK)
> tmp="Success.";
> else if(hrr==E_INVALIDARG)
> tmp="One or more arguments is invalid.";
> else tmp="some thing else happend";
> tmp ="cosetproxyblanket result of iwbemservices : "+tmp;
> AfxMessageBox(tmp);
> tmp="";
> IEnumWbemClassObject *icobj=NULL;
> BSTR wql=_bstr_t(_T("WQL"));
> IEnumWbemClassObject *pEnumServices = NULL;
> // MyIWbemObjectSink *objsink=NULL; ****  I implemented this class for 
> IWbemObjectSink n I kept it aside as its not working for me.
> MyIWbemObjectSink *msink=new MyIWbemObjectSink();
> msink->AddRef();
> IWbemObjectSink *objsink=msink;
>
> IEnumWbemClassObject *enumclsobj=NULL;
> hrr=iserv->ExecNotificationQuery(wql,details.query,WBEM_FLAG_FORWARD_ONLY 
> | WBEM_FLAG_RETURN_IMMEDIATELY,0,&enumclsobj);
> DWORD ddw=GetLastError();
> if(hrr==WBEM_E_ACCESS_DENIED) AfxMessageBox((CString)"The current user is 
> not authorized to view the result set. ");
> else if(hrr==WBEM_E_FAILED) AfxMessageBox((CString)"This indicates other 
> unspecified errors. ");
> else if(hrr==WBEM_E_INVALID_CLASS) AfxMessageBox((CString)"The query 
> specifies a class that does not exist. ");
> else if(hrr==WBEM_E_INVALID_PARAMETER) AfxMessageBox((CString)"An invalid 
> parameter was specified. ");
> //if(hrr==WBEM_E_REGISTRATION_TOO_PRECISE) AfxMessageBox((CString)"Too 
> much precision in delivery of events has been requested. A larger polling 
> tolerance should be specified. ");
> //if(hrr==WBEM_E_REGISTRATION_TOO_BROAD) AfxMessageBox((CString)"The query 
> requests more information than Windows Management can reasonably provide. 
> This message is returned when an event query results in a request to poll 
> all objects in a namespace. ");
> else if(hrr==WBEM_E_INVALID_QUERY) AfxMessageBox((CString)"The query was 
> not syntactically valid. ");
> else if(hrr==WBEM_E_INVALID_QUERY_TYPE) AfxMessageBox((CString)"The 
> requested query language is not supported. ");
> else if(hrr==WBEM_E_OUT_OF_MEMORY) AfxMessageBox((CString)"There was not 
> enough memory to complete the operation. ");
> else if(hrr==WBEM_E_TRANSPORT_FAILURE) AfxMessageBox((CString)"This 
> indicates the failure of the remote procedure call (RPC) link between the 
> current process and Windows Management. ");
> else if(hrr==WBEM_E_SHUTTING_DOWN) AfxMessageBox((CString)"Windows 
> Management service was probably stopped and restarted. A new call to 
> ConnectServer is needed. ");
> else if(hrr==WBEM_E_UNPARSABLE_QUERY) AfxMessageBox((CString)"The query 
> could not be parsed. ");
> else if(hrr==WBEM_S_NO_ERROR) AfxMessageBox((CString)"The call 
> succeeded.in sync. notification query ");
> else AfxMessageBox((CString)"something else happend here");
> //here the out put is something else happend here.
>
>
> /*
>
> hrr=iserv->ExecNotificationQueryAsync(wql,details.query,WBEM_FLAG_SEND_STATUS,NULL,objsink);
> DWORD ddw=GetLastError();
> if(hrr==WBEM_E_FAILED) tmp="This indicates other unspecified errors. ";
> else if(hrr==WBEM_E_INVALID_CLASS) tmp="The query specifies a class that 
> does not exist. ";
> else if(hrr==WBEM_E_INVALID_PARAMETER) tmp="An invalid parameter was 
> specified. ";
> //else if(hrr==WBEM_E_REGISTRATION_TOO_PRECISE) tmp="Too much precision in 
> delivery of events has been requested. A larger polling tolerance should 
> be specified. ";
> //else if(hrr==WBEM_E_REGISTRATION_TOO_BROAD) tmp="The query requests more 
> information than WMI can reasonably provide. This message is returned when 
> an event query results in a request to poll all objects in a namespace. ";
> else if(hrr==WBEM_E_INVALID_QUERY) tmp="The query was not syntactically 
> valid. ";
> else if(hrr==WBEM_E_INVALID_QUERY_TYPE) tmp="The requested query language 
> is not supported. ";
> else if(hrr==WBEM_E_OUT_OF_MEMORY) tmp="There was not enough memory to 
> complete the operation. ";
> else if(hrr==WBEM_E_SHUTTING_DOWN) tmp="Windows Management service was 
> probably stopped and restarted. A new call to ConnectServer is needed. ";
> else if(hrr==WBEM_E_TRANSPORT_FAILURE) tmp="This indicates the failure of 
> the remote procedure call (RPC) link between the current process and 
> Windows Management. ";
> else if(hrr==WBEM_E_UNPARSABLE_QUERY) tmp="The query could not be parsed. 
> ";
> else if(hrr==WBEM_S_NO_ERROR) tmp="The call succeeded. ";
> else tmp="something else happend";
> tmp ="execnotificationqueryasync  result : "+tmp;
> AfxMessageBox(tmp);
> */
>
> iserv->CancelAsyncCall(objsink);
> objsink->Release();
> return true;
> } 


Relevant Pages

  • RE: Any good T-SQL quick reference recommended?
    ... The full syntax of the SELECT ... SELECT Clause ... Specifies the columns to be returned by the query. ... Specifies that duplicate rows can appear in the result set. ...
    (microsoft.public.sqlserver.programming)
  • RE: iis crash/hang agent
    ... ;;; which is represented by a request that takes too long to complete. ... In the case of a hang, the agent can write a log file ... Configure the IISCHAgent.dll as a global filter in IIS by running ... Specifies the maximum number of CrashAgent logs to keep. ...
    (microsoft.public.inetserver.iis)
  • Return Hierarchical Data From One Table (with a JOIN to a second table)
    ... I would appreciate help in designing an efficient query that will retrieve ... [SequenceInRank] ... - specifies which row is the logical parent of the ...
    (microsoft.public.sqlserver.programming)
  • Re: Allen Browne - Help with duplicating Form & Subform!
    ... INSERT INTO tblPattern(PAT_NO, PAT_SIZE, QUANTITY) SELECT PAT_NO, ... I am certain that it is because of the request number, ... When I created table pattern I wanted to create a unique index on the entire ... and paste it into a new query. ...
    (microsoft.public.access.formscoding)
  • Re: Append query with no results
    ... There are records in [Refill Request] that do not have matches in [Chart Pull - Request]? ... I have also run the query as a select only query. ...
    (microsoft.public.access.queries)

Quantcast