|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
From: Sankar Ramanathan (sankar.ramanathan_at_RAPISTAN.COM)
Date: Thu Aug 01 2002 - 13:06:19 CDT
Hello All
Sorry about the OT.
I am trying to access the properties of Logical Disks using WMI. The
following is the code snippet in VB which works without any problems.
==============================================================================================================
Private Sub Form_Load()
Dim lWMILocator As WbemScripting.SWbemLocator
Dim lWMIServices As WbemScripting.SWbemServices
Dim lWMIObjectSet As WbemScripting.SWbemObjectSet
Dim lWMIObject As WbemScripting.SWbemObject
Set lWMILocator = New WbemScripting.SWbemLocator
Set lWMIServices = lWMILocator.ConnectServer(".", "ROOT\CIMV2")
Set lWMIObjectSet = lWMIServices.InstancesOf("Win32_LogicalDisk")
For Each lWMIObject In lWMIObjectSet
Debug.Print lWMIObject.Name
Next
End Sub
==============================================================================================================
I can get the names of the logical disks in the system.
Following is a C++ snippet of the code which tries to perform the same functionality.
==============================================================================================================
IWbemLocator* pWbemLocator = 0;
CComBSTR lNameSpace("root\\cimv2"); // Default namespace
IWbemServices* pWbemServices = 0;
IEnumWbemClassObject* pEnumWbemClassObject = 0;
IErrorInfo* pErrorInfo = 0;
HRESULT hRes = E_FAIL;
hRes = CoCreateInstance(__uuidof(WbemLocator),NULL,CLSCTX_INPROC_SERVER,__uuidof(IWbemLocator),(LPVOID*)(&pWbemLocator));
if SUCCEEDED(hRes)
{
try
{
hRes = pWbemLocator->ConnectServer(lNameSpace,NULL,NULL,NULL,0,NULL,NULL,&pWbemServices);
if ( FAILED ( hRes ) )
{
pWbemLocator->Release();
}
else
{
if ( pWbemServices != 0 )
{
IWbemClassObject* pObj = 0;
BSTR bstrPath = SysAllocString(L"Win32_LogicalDisk.DeviceID=\"D:\"");
hRes = pWbemServices->GetObject(bstrPath,0,0, &pObj, 0);
// hRes returns 0x80041003
// Display the object
BSTR bstrDriveObj;
hRes = pObj->GetObjectText(0, &bstrDriveObj);
printf("%S\n\n", bstrDriveObj);
pObj->Release();
pObj = NULL;
}
}
}
}
// catch block omitted for clarity
==============================================================================================================
In the call to pWbemServices->GetObject an error of 0x80041003 is returned which according to MSDN documentation is
WBEM_E_ACCESS_DENIED
The current user does not have permission to perform the action
I am logged in as administrator and I do not understand the reason for this error. What could be wrong?
Any help would be appreciated.
TIA
-Sankar
----------------------------------------------------------------
Users Guide http://discuss.microsoft.com/archives/mailfaq.asp
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:DCOM-signoff-request
DISCUSS.MICROSOFT.COM
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]