|
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
|
|
|
|
|
Sorry for a very delayed reply. I, in fact havent done these things to this extent. Therefore, I am not sure what might be the problem. I will have a look at it and will see what might be the problem.
Regards,
Aamir
|
|
|
|
|
Thanks Aamir,
I think I´ve found the problem. Now it works, but I don´t know if it´s correct. I´m going to explain myself again:
I extract the information in 5 steps:
Step 1: COM initialization
Step 2: Set COM Security level
Step 3: Create IWbemLocator interface
Step 4: Create IWbemServices interface using this Locator (ConnectServer)
Step 5: Set Proxy Security
Extract the desired information using one of the available methods (ExecQuery, GetObject ...)
I want to read information from root/default, root/CIMv2 and root/CIMv2/Applications/MicrosoftIE namespaces. It´s necessary to use the ConnectServer method for every namespace. At this point I got the error I refered in my first post.
To solve this I have tried the following :
When you want to change to another namespace you only have to repeat two steps, 4 and 5:
Step 4:(IWbemLocator::ConnectServer)
hres = pLoc->ConnectServer(bstrNamespace,
bstrUser,
bstrPasswd,
NULL,
NULL, // Security flags.
0, // Authority (e.g. Kerberos)
0, // Context object
&pSvc // pointer to IWbemServices
);
Step 5: ( IWbemLocator::CoSetProxyBlanket)
Both using the same IWbemLocator* interface created previously.
The problem appears in the step 4 (ConnectServer). You can´t send the bstrUser/bstrPasswd again. It´s necesary for the first time (root/default), but the second (root/cimv2) and subsequent you have to change these parameters to NULL/NULL:
hres = pLoc->ConnectServer(bstrNamespace,
NULL,
NULL,
NULL,
NULL, // Security flags.
0, // Authority (e.g. Kerberos)
0, // Context object
&pSvc // pointer to IWbemServices
);
It works fine in this way.
Do you know a correct way to do this?
Thanks in advance for your time
AngelM
|
|
|
|
|
Hi I am using VC6 with WMISDK installed. However, when I am trying to compile the program, it happends to show the following error message
Using WMIDlg.cpp
C:\Documents and Settings\tikcire\Desktop\WMI\Using_WMI\Using WMIDlg.cpp(184) : error C2065: 'CoInitializeSecurity' : undeclared identifier
C:\Documents and Settings\tikcire\Desktop\WMI\Using_WMI\Using WMIDlg.cpp(191) : error C2065: 'EOAC_NONE' : undeclared identifier
Error executing cl.exe.
I know CoInitializeSecurity is being defined at ObjBase.h, which is already included in SDK\include folder. Do you guys know why is that? And what's wrong with my project setting?
Thanks.
tikcireviva
|
|
|
|
|
Have u included wbemuuid.lib in linking libs. I dont know whether WMISDK puts default paths for these libs in the VC environment or not. So, please check it.
Regards,
Aamir
|
|
|
|
|
hi
hi
i have the same problem as the user above whom you replied to. i am using vc++6 and the required SDK.
i have other examples of code that have CoInitializeSecurity and i dont get any compile errors. in "using wmidlg.cpp" i have added two lines as below to try and resolve the problem but no luck. i cant see an option to add additional dependecies in vc++6 so below should do the same?
#define _WIN32_DCOM
#pragma comment(lib, "wbemuuid.lib")
please help
|
|
|
|
|
_WIN32_DCOM should be define in "Project Setting >> Preprocessor definitions"
wewqewqe
|
|
|
|
|
That sorted it out for me thanks xiaozhijian!
|
|
|
|
|