I have this code that I am trying to compile, but I am getting the
following errors
'CoInitializeSe curity': identifier not found
'EOAC_NONE' : undeclared identifier
I have pasted the code below
// Using_WMI1.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include "wbemidl.h"
#include <comdef.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
void OnButtonGetinfo ()
{
// TODO: Add your control notification handler code here
CoInitialize(NU LL);
//Security needs to be initialized in XP first and this was the major
problem
//why it was not working in XP.
if(CoInitialize Security( NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEV EL_PKT,
RPC_C_IMP_LEVEL _IMPERSONATE,
NULL,
EOAC_NONE,
0)
!= S_OK)
return;
IWbemLocator * pIWbemLocator = NULL;
IWbemServices * pWbemServices = NULL;
IEnumWbemClassO bject * pEnumObject = NULL;
BSTR bstrNamespace = (L"root\\cimv2" );
if(CoCreateInst ance (
CLSID_WbemAdmin istrativeLocato r,
NULL ,
CLSCTX_INPROC_S ERVER | CLSCTX_LOCAL_SE RVER ,
IID_IUnknown ,
( void ** ) & pIWbemLocator
) != S_OK)
return;
if(pIWbemLocato r->ConnectServe r(
bstrNamespace, // Namespace
NULL, // Userid
NULL, // PW
NULL, // Locale
0, // flags
NULL, // Authority
NULL, // Context
&pWbemServic es
) != S_OK)
return;
HRESULT hRes;
// BSTR strQuery = (L"Select * from win32_Processor ");
BSTR strQuery = (L"SELECT * FROM Win32_Operating System");
// BSTR strQuery = (L"SELECT Name, ProcessId, Caption, ExecutablePath"
FROM Win32_Process") ;
// BSTR strQuery = (L"SELECT * FROM Win32_Process") ;
BSTR strQL = (L"WQL");
hRes = pWbemServices-
>ExecQuery(strQ L,strQuery,WBEM _FLAG_RETURN_IM MEDIATELY,NULL, &pEnumObject );if(hRes != S_OK)
{
printf("Could not execute Query");
return;
}
ULONG uCount = 1, uReturned;
IWbemClassObjec t * pClassObject = NULL;
hRes = pEnumObject->Reset();
if(hRes != S_OK)
{
printf("Could not Enumerate");
return;
}
hRes = pEnumObject->Next(WBEM_INFI NITE,uCount, &pClassObjec t,
&uReturned);
if(hRes != S_OK)
{
printf("Could not Enumerate");
return;
}
VARIANT v1;
BSTR strClassProp = SysAllocString( L"NumberOfProce sses");
hRes = pClassObject->Get(strClassPr op, 0, &v1, 0, 0);
if(hRes != S_OK)
{
printf("Could not Get Value");
return;
}
SysFreeString(s trClassProp);
_bstr_t bstrPath = &v1; //Just to convert BSTR to ANSI
char* strPath=(char*) bstrPath;
if (SUCCEEDED(hRes ))
printf(strPath) ;
else
printf("Error in getting object");
VariantClear( &v1 );
pIWbemLocator->Release();
pWbemServices->Release();
pEnumObject->Release();
pClassObject->Release();
CoUninitialize( );
}
int _tmain(int argc, _TCHAR* argv[])
{
OnButtonGetinfo ();
return 0;
}
Any help I can get will be appreciated. Thanks