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
}
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
}