|
When I compile the code it gives following errors.
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\comdef.h(695) : error C2065: 'IAsyncSetup' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\comdef.h(710) : error C2065: 'IClassAccess' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\comdef.h(712) : error C2065: 'IClassAdmin' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\comdef.h(715) : error C2065: 'IClassRefresh' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\comdef.h(750) : error C2065: 'IEnumClass' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\comdef.h(762) : error C2065: 'IEnumPackage' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\comdef.h(1078) : error C2065: 'IXMLElementNotificationSink' : undeclared identifier
please help in fixing this error.
|
|
|
|
|
Hi,
Basically they are defined in 'ObjIdl.Idl'.
Try to locate that in your system. It is a part of SDK.
Make sure one of those paths are included in you visual studio(Tools->options->Directories.)
I defined 'D:\Program Files\Microsoft SDK\include' into it and my errors got resolved.
Priya Sundar
|
|
|
|
|
Under VC6, I had to add in my stdafx.h
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
I also had to add "wbemuuid.lib" to my libs to make this compile.
--
Chizl
|
|
|
|
|
Hi,
I have the right access settings at the remote machine but still I am unable to make remote connection. I gave as
BSTR bstrNamespace = (L"\\\\10.224.215.123\\root\\cimv2");
and then gave the user id and password while connecting to server.
Please help.
Thanks
|
|
|
|
|
Hi, This code works well on XP without any issues,
but it is not working under windows 2000 environment,
as amir said this code is intended to be written in win 2k, but
it is not working under win 2k, what iam missing here,
Can anyone help me.
bhavani
|
|
|
|
|
I´m still have the same problem, it didn't work on Windows 2000 / SP4, the "CoCreateInstance" faild.
Any ideas ?
Thank you,
regards
Marcus
|
|
|
|
|
I got it.
In my case it helps to do some smaller changes like follow :
<br />
if(CoCreateInstance (<br />
CLSID_WbemLocator,<br />
NULL ,<br />
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER , <br />
IID_IWbemLocator ,<br />
( void ** ) &pIWbemLocator<br />
) != S_OK)<br />
Change to "CLSID_WbemLocator" and "IID_IWbemLocator"
<br />
_bstr_t strQuery = sWQL.AllocSysString();<br />
_bstr_t strQL = _T("WQL");<br />
<br />
hRes = pWbemServices->ExecQuery(strQL, strQuery, WBEM_FLAG_DIRECT_READ,NULL,&pEnumObject);<br />
Change Type to "_bstr_t" and access to "WBEM_FLAG_DIRECT_READ" (i think the access mode not realy affected the issue)
Regards
Marcus
|
|
|
|
|
HI, iam very by seeing your code which is written in VC++, i have searched for this system information but anywhere in the net it is written in the vb 6 and c#, the one i got is yoours,
I am very thankful for your code.
and one thing you said that, it is intended to work in windows 2000, but for me it is worked properly in wndows XP in the first attempt after loading all .h and dll files,
but it is not working in windows 2000 os it seems, can u suggest me in this regard.
Thanks in advance
bhavani
|
|
|
|
|
i apply to call WMI(Win32_PingStatus) in MFC Extension DLL.
error message:
'CoInitializeEx failed'
your help is greatly appreciated.
|
|
|
|
|
Any idea what the proper namespace to gather this info for Vista?
|
|
|
|
|
Under Windows XP professional upon loading the UsingWMIExecutable i get a missing MFC71D.DLL error.
When i start the build process under Visual C++ 6.0, Visual C++ 6.0 misses the wbemidl.h file.
Is there any component which has to be installed additionally to make the example run?
Kind regards
Peter
|
|
|
|
|
This executable was built using Visual C++ 2003 (or 7.1 as they call it). You need to have MFC 7.1 dlls to run this exe.
For missing wbemidl.h file, u need to install the latest platform sdk to get the latest headers and libs. As I told u, this was built using Visual C++ 2003, therefore, it will work perfectly in that version of Visual C++. For others, you can copy/paste the code and may find some alternatives which I am sure there will be.
"Some people believe football is a matter of life and death.
I'm very disappointed with that attitude.
I can assure you it is much, much more important than that. -- Bill Shankly"
|
|
|
|
|
Hi! Help me please to recognize situation : CPU USAGE 0%, all windows are not responding when IEXPLORE waiting for timeout(or searching the net) by using WMI or if i should not use WMI on this case,tell me PLZ how i could do it. Thank you !
|
|
|
|
|
...(Connect a remote server).....
IEnumWbemClassObject* pEnumerator = NULL;
HRESULT hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT top 1 * FROM Win32_NTLogEvent"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres)) //Failed : hres==0x80070005
...
if connect the local server,it works correct.
toyclub@sina.com
|
|
|
|
|
I had a big problem getting a similar thing to work in my MFC application, sat almost a whole day . The reason was that the #define _WIN32_DCOM had to be in the stdafx.h file. Putting anywhere else didn't work but returned the error: "error C2065: 'CoInitializeEx' : undeclared identifier". Just a notice if somebody else runs into the same problem.
|
|
|
|
|
hi
try to run using release version instead of debug version.
|
|
|
|
|
good post SpitFireX...
it gave me a solution on a different problem...
see my prob was with an undefined CoInitializeSecurity(...)
i was thinking it could be skipped via #ifndef _WIN32_DCOM directive
which later gave only limited queries and in the end not getting what i wanted...
your post made me realize skipping was a big no, no...
my bad...
|
|
|
|
|
Any one know how to actually get string value for IP Address from Win32_NetworkAdapterConfiguration object. It is stored as an array. I guess I don't know how to actually retrieve the array from the variant object?
your help is greatly appreciated.
Diana.
|
|
|
|
|
It really depends on what is stored in the variant. You can check this by checking the vt of the variant. If it is VT_ARRAY|VT_VARIANT, then surely there is a SafeArray inside the variant. You will have to checkout methods of extracting the data from the SafeArray for this.
Regards,
There are two types of roads in our country. One
is under construction and the other is under repair.
|
|
|
|
|
Im really new in wmi programming using c++. Can you provide code snippets on how to check the vt of the variant and how to extract the data from the SafeArray. Thanks.
Expect the worst, and hope for the best.
|
|
|
|
|
hope that can help:
<br />
hres = pSvc->ExecQuery(<br />
bstr_t("WQL"), <br />
bstr_t("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'"),<br />
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, <br />
NULL,<br />
&pEnumerator);<br />
<br />
if (FAILED(hres))<br />
{<br />
pSvc->Release();<br />
pLoc->Release();<br />
CoUninitialize();<br />
return -1; <br />
}<br />
<br />
int nRez = 0;<br />
char sRezDescr[256] = {'\0'};<br />
char sRezModel[128] = {'\0'};<br />
<br />
szTmp = "";<br />
while (pEnumerator)<br />
{<br />
VARIANT vtProp;<br />
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, <br />
&pclsObj, &uReturn);<br />
<br />
if(0 == uReturn) break;<br />
<br />
<br />
hr = pclsObj->Get(L"IPEnabled", 0, &vtProp, 0, 0);<br />
if(vtProp.boolVal)<br />
{ <br />
LONG lstart, lend;<br />
LONG idx = -1;<br />
BSTR* pbstr;<br />
SAFEARRAY *sa;<br />
<br />
hr = pclsObj->Get(L"Description", 0, &vtProp, 0, 0);<br />
if(!FAILED(hr))<br />
wcout << "Description: " << vtProp.bstrVal << endl; <br />
<br />
<br />
hr = pclsObj->Get(L"DNSHostName", 0, &vtProp, 0, 0);<br />
if(!FAILED(hr))<br />
wcout << "DNS:" << vtProp.bstrVal << endl;<br />
<br />
hr = pclsObj->Get(L"IPAddress", 0, &vtProp, 0, 0);<br />
<br />
sa = vtProp.parray; <br />
<br />
hr = SafeArrayGetLBound( sa, 1, &lstart );<br />
if(FAILED(hr)) return hr;<br />
hr = SafeArrayGetUBound( sa, 1, &lend );<br />
if(FAILED(hr)) return hr;<br />
<br />
hr = SafeArrayAccessData(sa,(void HUGEP**)&pbstr);<br />
if(SUCCEEDED(hr))<br />
{<br />
for(idx=lstart; idx <= lend; idx++)<br />
wcout << "IP:" << pbstr[idx] << endl;<br />
hr = SafeArrayUnaccessData(sa); <br />
}<br />
<br />
hr = pclsObj->Get(L"IPSubnet", 0, &vtProp, 0, 0);<br />
sa = vtProp.parray; <br />
<br />
hr = SafeArrayGetLBound( sa, 1, &lstart );<br />
if(FAILED(hr)) return hr;<br />
hr = SafeArrayGetUBound( sa, 1, &lend );<br />
if(FAILED(hr)) return hr;<br />
<br />
hr = SafeArrayAccessData(sa,(void HUGEP**)&pbstr);<br />
if(SUCCEEDED(hr))<br />
{<br />
for(idx=lstart; idx <= lend; idx++)<br />
wcout << "SUBNET:" << pbstr[idx] << endl;<br />
hr = SafeArrayUnaccessData(sa); <br />
}<br />
<br />
<br />
hr = pclsObj->Get(L"DefaultIPGateway", 0, &vtProp, 0, 0);<br />
sa = vtProp.parray; <br />
<br />
hr = SafeArrayGetLBound( sa, 1, &lstart );<br />
if(FAILED(hr)) return hr;<br />
hr = SafeArrayGetUBound( sa, 1, &lend );<br />
if(FAILED(hr)) return hr;<br />
<br />
hr = SafeArrayAccessData(sa,(void HUGEP**)&pbstr);<br />
if(SUCCEEDED(hr))<br />
{<br />
for(idx=lstart; idx <= lend; idx++)<br />
wcout << "GATEWAY:" << pbstr[idx] << endl;<br />
hr = SafeArrayUnaccessData(sa); <br />
<br />
}<br />
}<br />
VariantClear(&vtProp);<br />
}<br />
<br />
if(pEnumerator)<br />
pEnumerator->Release();<br />
if(pclsObj)<br />
pclsObj->Release();<br />
<br />
<br />
|
|
|
|
|
Hi,
First: :-DThank you for the enlightning sample!!!
Second: while the downloaded executable works properly, I get "Could not Enumerate" when I run the compiled code from VC++ 6.0,
when I step into pWbemServices->ExecQuery I get a messagebox labled "Just-In-Time Debugging" saying: "An exception 'Unhandeled win32 exception' has occurred in svchost.exe
Any Ideas why this happenes?
thanks, Isaac
|
|
|
|
|
Looks like you are not getting a valid pointer to pWbemServices. Check the output of the previous method i.e., ConnectServer(...) and see what it gives. Looks to be an error there
Regards,
Aamir
|
|
|
|
|
thanks, but this is not the case.
I get pointers and S_OK results for pWbemServices and for pEnumObject.
only the pClassObject gets a NULL pointer....
|
|
|
|
|
Hi !
This is the best sample i´ve found based on C++. It works fine.
I have modified it to collect HW and SW info on several PC´s and i have found a little problem when i try to change to another namespace
First I create the Locator Object in this way:
IWbemLocator* pLoc = NULL;
hres = CoCreateInstance(CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator,
(LPVOID *) &pLoc);
Then I use it to get information from \\root\\cimv2
IWbemServices* pSvc = NULL;
hres = pLoc->ConnectServer(L"\\root\\cimv2",
bstruser,
bstrpasswd,
NULL,
NULL,
0,
0,
&pSvc
);
All works fine. But when I try to connect to the namespace:
\\root\\cimv2\\Applications\\MicrosoftIE
I get 'Access denied' although there is no difference between the permissions on both namespaces.
I am reusing the same interfaces, pLoc and pSvc
hres = pLoc->ConnectServer(L"\\root\\cimv2\\Applications\\MicrosoftIE",
bstruser,
bstrpasswd,
NULL,
NULL,
0,
0,
&pSvc
);
Have you found an error like this?
Do I have to create a new instance of the Locator Object to connect to the new namespace or can i use the same ?
Do I have to create another interface to the IWBemServices, pSvc?
(I have tried this, but i get the same error, 0x80070005)
Thanks in advance
AngelM
AngelM
-- modified at 9:13 Monday 14th November, 2005
|
|
|
|
|