|
hi,
i am working with the code given by aamir butt.
i have vc6
and i have microsoft sdk xp sp2
i selected win32 console application that has mfc support.
My problem is while compiling the code,the following error is coming
Linking...
Wbemuuid.lib(wbemcli_i.obj) : fatal error LNK1103: debugging information corrupt; recompile module
Error executing link.exe.
i have written only a fraction of code given by butt
i only included the functions
- coinitialize
- coinitializesecurity and
- cocreateinstance
when i removed 'cocreateinstance' and compiled, it is not giving errors
i read the articles given here
and tried the first argument with 'CLSID_WbemLocator' and
'CLSID_WbemAdministrativeLocator'.
but no use
i need it for my final sem project
please help me.
following is my code
::CoInitialize(NULL);
if(CoInitializeSecurity( NULL,-1,NULL,NULL,RPC_C_AUTHN_LEVEL_PKT,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE,0) != S_OK)
return -1;
IWbemLocator * pIWbemLocator = NULL;
IWbemServices * pWbemServices = NULL;
IEnumWbemClassObject * pEnumObject = NULL;
BSTR bstrNamespace = (L"root\\cimv2");
HRESULT hRes = CoCreateInstance (CLSID_WbemLocator,
NULL ,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER , IID_IUnknown ,
( void ** ) & pIWbemLocator ) ;
|
|
|
|
|
Had the same problem last weekend.
Looks like the DDK having a problem.
I found an older version of the library which seems to work better:
24-Jun-04 15:37 32,100 WbemUuid.Lib
Sorry, but can't remember where I downloaded it from.
If you can't find that version, let me know (beecken@image.dk) and I'll send you a copy of my version.
--> Don't like this work around as I don't know what side effects it has.
Regards
Peter Beecken
|
|
|
|
|
I realize I'm responding to an OLD message, but apparently the problem has still not been fixed. Does anyone know of a fix for this? Does anyone know where an older, non-corrupted copy of this library may be obtained.
Thanks to all for any help or advice you can offer.
Jeff Nygren
|
|
|
|
|
Jeff Nygren:
I have fixed this problem by copy wbemuuid.lib from VC.net(VC7) as the first reply said. You can send me a E_mail (pilixuanke@gmail.com) to request this file if u can't get it by yourself.
|
|
|
|
|
i have vc++ 6.0 and sdk xp sp2
when i copied and run the code given by Aamir Butt,
i got the link error saying "object file is corrupted, recompile the code"
compilation is ok
but linking is the problem
any suggestions?
bye
visu
|
|
|
|
|
The following is a copy of my post in COM message board. Please, help ....
Has anyone been successful in executing the
Win32_OperatingSystem class method "Reboot" or "Shutdown" from a call to the ExecMethod routine in C++. This method works fine using VBScript. But in C++, the method returns an error in ExecMethod - WBEM_E_INVALID_METHOD_PARAMETERS.
Why ?
Here is my code :
...
HRESULT hr;
CComPtr<IWbemLocator> pLocator;
CComPtr<IWbemServices> pServices;
CComBSTR bstrPath = L"//";
bstrPath.AppendBSTR(bstrComputer);
bstrPath.Append(L"/root/cimv2");
CComBSTR bstrObject = L"Win32_OperatingSystem";
CComBSTR bstrMethod = L"Win32Shutdown";
CComBSTR bstrLanguage = SysAllocString(L"WQL");
CComBSTR bstrQuery = SysAllocString(L"select * from Win32_OperatingSystem where Primary=true");
CComBSTR bstrFlags = L"Flags";
CComBSTR bstrReserved = L"Reserved";
hr = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hr))
{
cout << "Failed in CoInitializeEx" << endl;
return hr;
}
hr = CoInitializeSecurity(
NULL,
-1, // COM negotiates service
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
);
if (FAILED(hr))
{
cout << "Failed in CoInitializeSecurity" << endl;
CoUninitialize();
return hr;
}
//get the initial namespace of the CIM Object Manager
hr = pLocator.CoCreateInstance(__uuidof(WbemLocator), 0, CLSCTX_INPROC_SERVER);
if (FAILED(hr)){
cout << "Failed in CoCreateInstance" << endl;
return hr;
}
//create an instance for the interface that connects WBEM services
hr = pLocator->ConnectServer(bstrPath, NULL, NULL, NULL, 0, NULL, NULL, &pServices);
if (FAILED(hr)){
cout << "Failed in ConnectServer" << endl;
return hr;
}
//authenticate to the service, using current credentials
hr = CoSetProxyBlanket(pServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE);
if (FAILED(hr)){
cout << "Failed in CoSetProxyBlanket" << endl;
return hr;
}
//query WMI for objects: get the Win32_OperatingSystem class using WQL
CComPtr<IEnumWbemClassObject> pEnumWbem;
hr = pServices->ExecQuery(bstrLanguage, bstrQuery, WBEM_FLAG_FORWARD_ONLY, NULL, &pEnumWbem);
if (FAILED(hr)){
cout << "Failed in ExecQuery" << endl;
return hr;
}
//for each returned object call Win32Shutdown
IWbemClassObject* pWbemObject;
DWORD nRetObjects;
pEnumWbem->Reset();
while (pEnumWbem->Next(WBEM_INFINITE, 1, &pWbemObject, &nRetObjects) == S_OK)
{
CComPtr<IWbemClassObject> pClass;
CComPtr<IWbemClassObject> pMethod;
CComPtr<IWbemClassObject> pInParams;
CComPtr<IWbemClassObject> pOutParams;
//get the class definition of Win32_OperatingSystem
hr = pServices->GetObject(bstrObject, 0, NULL, &pClass, NULL);
if (FAILED(hr))
{
cout << "Failed in GetObject" << endl;
pWbemObject->Release();
return hr;
}
//get our method
hr = pClass->GetMethod(bstrMethod, 0, &pMethod, NULL);
if (FAILED(hr))
{
cout << "Failed in GetMethod" << endl;
pWbemObject->Release();
return hr;
}
//create a new object for in parameters
hr = pMethod->SpawnInstance(0, &pInParams);
if (FAILED(hr))
{
cout << "Failed in SpawnInstance" << endl;
pWbemObject->Release();
return hr;
}
//add parameters
CComVariant var;
V_VT(&var) = VT_I4;
V_I4(&var) = (short)nAction;
hr = pInParams->Put(bstrFlags, 0, &var, CIM_SINT32);
if (FAILED(hr))
{
cout << "Failed in Put" << endl;
pWbemObject->Release();
return hr;
}
//call Win32Shutdown with our action
hr = pServices->ExecMethod(bstrObject, bstrMethod, 0L, NULL, pInParams, &pOutParams, NULL);
if(hr == WBEM_E_INVALID_METHOD_PARAMETERS){
cout << "That's it" << endl;
}
if (FAILED(hr)){
cout << "Failed in ExecMethod" << endl;
pWbemObject->Release();
return hr;
}
pWbemObject->Release();
}
Code Red
|
|
|
|
|
???? mark
Any automation language, such as Visual Basic, VBScript, JScript, or Perl, can call a WMI method. Some languages can use direct access but others must use SWbemServices.ExecMethod to execute the provider method indirectly.
refer to MSDN ,I think
smart
|
|
|
|
|
Hi,
I have the same problem. Did you solved it? Please reply with the solution. Thanks!
|
|
|
|
|
hi...
i have problem...
dev env win2k .net(vc7.1)
CoInitializeSecurity(...) return error RPC_E_TOO_LATE
why...
|
|
|
|
|
You can go away without this method call in Win2K. So, u can safely delete this method call. However, there is an alternate as well:
Add _WIN32_DCOM define flag to preprocessor options
Add to the Using WMIDlg.cpp the following couple of include statements:
#include <ObjIdl.h>
#include <ObjBase.h>
You can find the answer to a similar question down in another thread by otchenash
Hope this will work
I hated going to weddings. All the grandmas would poke me saying "You're next". They stopped that when I started doing it to them at funerals.
My Articles
|
|
|
|
|
Hi,
everything with "Getting Information from WMI in Visual C++" works OK in my environment (Windows XP), but when I execute it under Windows 2000, I can only press the button "Get Processor Load ..." once in order to get the small dialog telling me the CPU load; the second and subsequent times I press this button, nothing happens.
This already happens with the executable that I downloaded, so I assume this to be a general problem.
What is wrong? Grateful for any hint, Axel.
|
|
|
|
|
My project doesnt compile because I dont have it file..
Anybody will help me
Thanks!
Alfredo Salvador
|
|
|
|
|
I think it is in the WMI SDK, which is part of the platform SDK. I had the same problem when I installed just the core SDK files.
|
|
|
|
|
when you install MS.net ,this file will be installed on
your conputer,the folder like:C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\
|
|
|
|
|
I often encountered followed problems
HRESULT hRes = CoCreateInstance (
CLSID_WbemAdministrativeLocator,
NULL ,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
IID_IUnknown ,
( void ** ) & pIWbemLocator
) ;
hRes sometimes does not equal to S_OK ,so can you tell me why
the result of SUCCEEDED(hRes)) sometimes <1
ttt
|
|
|
|
|
win2000 and vc6.0:
Using WMIDlg.cpp
C:\Documents and Settings\Administrator\桌面\Using_WMI\Using WMIDlg.cpp(185) : error C2065: 'CoInitializeSecurity' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\Using_WMI\Using WMIDlg.cpp(192) : error C2065: 'EOAC_NONE' : undeclared identifier
Error executing cl.exe.
Using WMI.exe - 2 error(s), 0 warning(s)
who can help me ?
|
|
|
|
|
Check that whether you have set the linker to wbemuuid.lib or not. Do it plz. to run this project. I have wrote that in update section of this Article already.
If you have done so, then Simply remove the call to CoInitializeSecurity.
Imagine that you are creating a fabric of human destiny with the object of making men happy in the end, giving them peace and rest at last, but that it was essential and inevitable to torture to death only one tiny creature..and to found that edifice on its unavenged tears, would you consent to be the architect on those conditions? Tell me, and tell me the truth!
-Fyodor Dostoevsky, The Brothers Karamazov
|
|
|
|
|
Thank you very much!
I have set the link to wbemuuic.lib,but there also have the same problem.
I have removed the call to CoInitializeSecurity,and now every thing is ok!
|
|
|
|
|
Add to the Using WMIDlg.cpp the following couple of include statements:
#include <ObjIdl.h>
#include <ObjBase.h>
Add _WIN32_DCOM define flag to preprocessor options
Add the Wbemuuid.lib to the list of linked libraries
After these three steps project will build correctly.
|
|
|
|
|
Thank you very much!
It's a good way to solve my problem,and now I need not to remove any code.
|
|
|
|
|
Using WMIDlg.cpp
C:\Documents and Settings\jploettner\Desktop\Using_WMI\Using WMIDlg.cpp(184) : error C2039: 'CoInitializeSecurity' : is not a member of '`global namespace''
C:\Documents and Settings\jploettner\Desktop\Using_WMI\Using WMIDlg.cpp(184) : error C2065: 'CoInitializeSecurity' : undeclared identifier
C:\Documents and Settings\jploettner\Desktop\Using_WMI\Using WMIDlg.cpp(191) : error C2065: 'EOAC_NONE' : undeclared identifier
Error executing cl.exe.
Using WMI.exe - 3 error(s), 0 warning(s)
Any susgestions would be greatly appreciated, I've been trying to figure WMI out forever!
Thanks for the example!
|
|
|
|
|
hi,
move the "platform sdk include: to the top of the list of include files
do the same with lib files.
they are located in the "options" of "tools" tab
there you can change them
bye
visu
|
|
|
|
|
The ONE and ONLY C++ code for using WMI on the Internet that works! I have been able to use your code to tailor it to my needs in an application I'm writing. The few C++ examples I found on the Internet did not run. They always seemed to be missing something that prevented them from building. It is 6AM Chicago time, and I'm in a very good mood thanks to the author.
ciaoroma
|
|
|
|
|
At last I found a person who has got it working in the first attempt without errors. You can't imagine how good I am feeling right now
Thanx to all of those who pointed out those bugs which I fixed in Update.
Think Negatively, It makes you creative
|
|
|
|
|
Hello,
I've also written code with Visual C++ to acces WMI which doesn't exactly work as yours.
In one of your answer, you suggest to replace CLSID_WbemAdministrativeLocator (which caused a link error) with CLSID_WbemLocator : why did you choose CLSID_WbemAdministrativeLocator ? what is it ?
NB: To compile your project, I've had to define _WIN32_WINNT>=0x0400.
An other possibility to get information from WMI (instead of calling the function ExecQuery) should be to use the IWbemLocator::GetObject operation to access a required instance (IWbemClassObject) then to use the IWbemClassObject::Get operation to access the property you want to read.
If needed, it is also possible to use the CoSetProxyBlanket operation to switch the security level.
NB: it is possible to update Windows NT (none reversible operation) to have access to WMI : I've done it successfully.
Philippe.
|
|
|
|
|