WMI Win32_LogicalDisk FreeSpace problem


A

Amit

Dear all,

I'm using WMI Win32_LogicalDisk for retrieving information about the
C: drive. On XP Pro everything works just fine, however, on XP
Embedded the FreeSpace, Size, and a few more properties return null
values.

I've tried this both in C# and in native C++. The behaviour is the
same. Any idea would be appreciated.

Bellow is the native C++ code I'm using (I removed all error handling
for better clarity). If you try it, note that FreeSpace, for instance,
is not printed on XPE.

TIA,

Amit


//--------------------------------------------------------------------------

#include "stdafx.h"

#define _WIN32_DCOM

#include <stdio.h>
#include <comdef.h>
#include <wbemidl.h>
#include <wbemcli.h>

#include <iostream>

using namespace std;


int test2()
{
HRESULT hr;
_bstr_t bstrNamespace;
IWbemLocator *pWbemLocator = NULL;
IWbemServices *pServices = NULL;
IWbemClassObject *pDrive = NULL;


hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

hr = CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_CONNECT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, EOAC_NONE, 0);

hr = CoCreateInstance(CLSID_WbemLocator, NULL,
CLSCTX_INPROC_SERVER, IID_IWbemLocator,
(void**) &pWbemLocator);

bstrNamespace = L"root\\cimv2";
hr = pWbemLocator->ConnectServer(bstrNamespace, NULL, NULL, NULL,
0, NULL, NULL, &pServices);

pWbemLocator->Release();
printf("Successfully connected to namespace.\n");

BSTR bstrPath = SysAllocString(L"Win32_LogicalDisk.DeviceID=\"C:\"");
hr = pServices->GetObject(bstrPath,
0,0, &pDrive, 0);

BSTR bstrDriveObj;
hr = pDrive->GetObjectText(0, &bstrDriveObj);
printf("%S\n\n", bstrDriveObj);

pDrive->Release();
pDrive = NULL;
pServices->Release();
pServices = NULL; // MUST be set to NULL
CoUninitialize();
return 0; // -- program successfully completed
}
 
Ad

Advertisements

K

KM

Amit,

I haven't seen the problem you mentioned but just a first hint: do you have "Disk Performance Counters" and "Performance Counter WMI Provider" components included in your image?

KM
BSquare Corporation

A> Dear all,

A> I'm using WMI Win32_LogicalDisk for retrieving information about the
A> C: drive. On XP Pro everything works just fine, however, on XP
A> Embedded the FreeSpace, Size, and a few more properties return null
A> values.

A> I've tried this both in C# and in native C++. The behaviour is the
A> same. Any idea would be appreciated.

A> Bellow is the native C++ code I'm using (I removed all error handling
A> for better clarity). If you try it, note that FreeSpace, for
A> instance, is not printed on XPE.

A> TIA,

A> Amit


A> //--------------------------------------------------------------------
A> ------

A> #include "stdafx.h"

A> #define _WIN32_DCOM

A> #include <stdio.h>
A> #include <comdef.h>
A> #include <wbemidl.h>
A> #include <wbemcli.h>

A> #include <iostream>

A> using namespace std;


A> int test2()
A> {
A> HRESULT hr;
A> _bstr_t bstrNamespace;
A> IWbemLocator *pWbemLocator = NULL;
A> IWbemServices *pServices = NULL;
A> IWbemClassObject *pDrive = NULL;


A> hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

A> hr = CoInitializeSecurity(NULL, -1, NULL, NULL,
A> RPC_C_AUTHN_LEVEL_CONNECT,
A> RPC_C_IMP_LEVEL_IMPERSONATE,
A> NULL, EOAC_NONE, 0);

A> hr = CoCreateInstance(CLSID_WbemLocator, NULL,
A> CLSCTX_INPROC_SERVER, IID_IWbemLocator,
A> (void**) &pWbemLocator);

A> bstrNamespace = L"root\\cimv2";
A> hr = pWbemLocator->ConnectServer(bstrNamespace, NULL, NULL, NULL,
A> 0, NULL, NULL, &pServices);

A> pWbemLocator->Release();
A> printf("Successfully connected to namespace.\n");

A> BSTR bstrPath =
A> SysAllocString(L"Win32_LogicalDisk.DeviceID=\"C:\"");
A> hr = pServices->GetObject(bstrPath,
A> 0,0, &pDrive, 0);

A> BSTR bstrDriveObj;
A> hr = pDrive->GetObjectText(0, &bstrDriveObj);
A> printf("%S\n\n", bstrDriveObj);

A> pDrive->Release();
A> pDrive = NULL;
A> pServices->Release();
A> pServices = NULL; // MUST be set to NULL
A> CoUninitialize();
A> return 0; // -- program successfully completed }
 
A

Amit

KM,

Thanks for your post. However, these components are already included
and the problem still persists. I'll keep trying...

Thanks,

Amit
 
S

Slobodan Brcin

Hi Amit,

Add to your code some message boxes that will tell you what command exactly
failed, and error code of failure.

This way you can see what is probably missing.

Regards,
Slobodan


Amit said:
KM,

Thanks for your post. However, these components are already included
and the problem still persists. I'll keep trying...

Thanks,

Amit

"KM" <[email protected]> wrote in message
have "Disk Performance Counters" and "Performance Counter WMI Provider"
components included in your image?
 
K

KM

I thought he has mentioned only null values returned for some properties and
assumed there was no error returned.
It is very possible if some of WMI components missing (not good error
handling).

Another thing is - spying (monitoring) system calls. I'd try RegMon first to
see what system components (e.g, COM objects) get requested and not getting
found. Also, the same thing is better to check with Filemon.
And one more good tool would be Kernel Debugger (or WinDbg). Some components
may throw useful debug output that may help fixing the problem. The point is
that KD remote debugger is easy to set up and never hurts to use :)

KM
 
S

Slobodan Brcin

Hi Konstantin,

He specifically said that he removed all error handling for our better
clarity, but we don't know anything about return values.
Also I fail to see properties he mentioned, in his code.

Checking HRESULT value could say what was the problem with failed call.

Using RegMon, or KD is probably the best thing to start with. Maybe he can
use remote debugging even from Visual Studio.

Regards,
Slobodan

BTW:
I'm little unresponsive of lately, my NNTP protocol does not work well in
last two weeks :(
 
Ad

Advertisements

A

Amit

I removed the error handling because, like Konstantin has suggested,
it was irrelevant. There are no errors - some of the values are simply
null. Anyway, the problem is now solved. A component called "Disk
Quota User Interface" was missing.

Thanks for the advice, though.

--- Amit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

wmi freespace property fails in xpe 2
wmi problem 1
WMI problem 1
WMI 1
WMI problems/missing components. 3
WMI 0
WMI Question 1
WMI with SP2 11

Top