if (FAILED(hres))
{
cout << "Could not connect. Error code = 0x"
<< hex << hres << endl;
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl;
// Set the IWbemServices proxy so that impersonation
// of the user (client) occurs.
hres = CoSetProxyBlanket(
pSvc, // the proxy to set
RPC_C_AUTHN_WINNT, // authentication service
RPC_C_AUTHZ_NONE, // authorization service
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_CALL, // authentication level
RPC_C_IMP_LEVEL_IMPERSONATE, // impersonation level
NULL, // client identity
EOAC_NONE // proxy capabilities
);
if (FAILED(hres))
{
cout << "Could not set proxy blanket. Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
// Use the IWbemServices pointer to make requests of WMI.
// Make requests here:
// For example, query for print queues that
// have more than 10 jobs
IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * Win32_BIOS "),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
cout << "Query for print queues failed. "
<< "Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
else
{
do
{
IWbemClassObject* pInstance = NULL;
ULONG dwCount = NULL;
1. What's the error you're receiving?
2. Can you put your code in a code tag?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
I made a few changes to the program (see attached):
Used the _COM_SMARTPTR_TYPEDEF macros defined in <comdef.h> to convert all the IWbemXXX interfaces to smart pointers - makes calling IWbemXXX->Release() unnecessary.
Used the _variant_t wrapper instead of VARIANT
Moved the IWbemClassObjectPtr->Get() call inside the do/while loop.
Changed the "Serial Number" property to "SerialNumber" as ShelleyWang suggested.
Moved the Bios retrieval code into a function so CoUninitialize doesn't get called before the smart pointers go out of scope (a scoping block would have worked equally as well).
Replaced the call to IWbemServices->ExecQuery() with a call to IWbemServices->CreateInstanceEnum(). I couldn't get the ExecQuery call to work with your code and I didn't have time to look into the Synchronous, Asynchronous, or SemiSynchronous modes. (As George Carlin once said: "It either flams or it doesn't flam." ). Anyway, CreateInstanceEnum works fine here.
Thanks a lot for your help. I really appreciate the time you spend or debugging this code. The code although is giving no errors, but it also not displaying the required BIOS information ..
I have two computer, one runs properly and get the right Serial Number, then other runs properly too but it cann't gets the Serial Number, it appears "none".
I don't know what's the mater with this program.
Anywhere , if you want the program, please give me you E-Mail address
I'd suggest installing the WMI Tools from the sdk and using the CIM Studio to determine if the SerialNumber property is actually set. Btw, did you run the modified wmii_test code that I attached. I tried it out on a couple of computers and it worked on both.
[Arjay revision] Actually it did work, but until I looked at the output and compared it with CIM Studio, I didn't know that Win32_BIOS is the wrong class to use. Instead use Win32_BaseBoard.
See the attachment for a sample that uses this data.
Hello Arjay, that was really considerate and kind of you to look into the code in detail. It helped a lot and you cant imagine that how accelerating that was in simulating an aspect of ma project. thanx a lot again, God bless ya!
Unfortunately, not as this time as it would take quite a bit of work to refactor it. I did write some similar code for a sample in another forum called Using WMI... The sample is in C#, but can be easily ported back to C++.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.