Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2007

Tip: Looking for answers? Try searching our database.

VC++ security problem using WMI

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Newsgroups - 21 Jun 2007 13:11 GMT
Hi,
I found some code from codeproject site using WMI in VC++.

I have created a method having the following code in it. It works fine when
I am running into "Admin" accound in Windows XP Pro while in "Restricted
user account", its not able to run. It's giving error messsage "Could not
enumerate" so it seems "pEnumObject" seems null or empty.
Please help,

Thanks in advance,

Code:
CoInitialize(NULL);
//Security needs to be initialized in XP first and this was the major
problem
//why it was not working in XP.
if(CoInitializeSecurity( NULL,
-1,

NULL,

NULL,

RPC_C_AUTHN_LEVEL_PKT,

RPC_C_IMP_LEVEL_IMPERSONATE,

NULL,

EOAC_NONE,

0

) != S_OK)

return;

IWbemLocator * pIWbemLocator = NULL;

IWbemServices * pWbemServices = NULL;

IEnumWbemClassObject * pEnumObject = NULL;

BSTR bstrNamespace = (L"root\\cimv2");

if(CoCreateInstance (

CLSID_WbemAdministrativeLocator,

NULL ,

CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,

IID_IUnknown ,

( void ** ) & pIWbemLocator

) != S_OK)

return;

if(pIWbemLocator->ConnectServer(

bstrNamespace, // Namespace

NULL, // Userid

NULL, // PW

NULL, // Locale

0, // flags

NULL, // Authority

NULL, // Context

&pWbemServices

) != S_OK)

return;

HRESULT hRes;

// BSTR strQuery = (L"Select * from Win32_PhysicalMedia");

BSTR strQuery = (L"Select * from Win32_PhysicalMedia");

BSTR strQL = (L"WQL");

hRes = pWbemServices->ExecQuery(strQL,
strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);

if(hRes != S_OK)

{

MessageBox("Could not execute Query");

return;

}

ULONG uCount = 1, uReturned;

IWbemClassObject * pClassObject = NULL;

hRes = pEnumObject->Reset();

if(hRes != S_OK)

{

MessageBox("Could not Enumerate");

return;

}

hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject, &uReturned);

if(hRes != S_OK)

{

MessageBox("Could not Enumerate");

return;

}

VARIANT v;

//BSTR strClassProp = SysAllocString(L"SerialNumber");

//Product

BSTR strClassProp = SysAllocString(L"SerialNumber");

hRes = pClassObject->Get(strClassProp, 0, &v, 0, 0);

if(hRes != S_OK)

{

MessageBox("Could not Get Value");

return;

}

SysFreeString(strClassProp);

_bstr_t bstrPath = &v; //Just to convert BSTR to ANSI

char* strPath=(char*)bstrPath;

if (SUCCEEDED(hRes))

{

VariantClear( &v );

pIWbemLocator->Release();

pWbemServices->Release();

pEnumObject->Release();

pClassObject->Release();

CoUninitialize();

return strPath;

}

else

{

MessageBox("Error in getting object");

return;

}

VariantClear( &v );

pIWbemLocator->Release();

pWbemServices->Release();

pEnumObject->Release();

pClassObject->Release();

CoUninitialize();

return;
Bruno van Dooren - 22 Jun 2007 11:18 GMT
Hi,

It's me again. You are almost there. I think the following groups are more
on topic for your question
microsoft.public.windowsxp.wmi
microsoft.public.win32.programmer.wmi
microsoft.public.platformsdk.security

And If you feel you have to ask in multiple groups simultaneously, please
cross post instead of multipost, otherwise people in one group will not be
able to see answers that were posted in the other group.

Signature

Kind regards,
   Bruno van Dooren  MVP - VC++
   http://msmvps.com/blogs/vanDooren
   bruno_nos_pam_van_dooren@hotmail.com

Newsgroups - 22 Jun 2007 13:32 GMT
Thanks a lot Bruno for your kind guidance.

Let me post it as you said. Thanks once again for help,

Regards,
Mahesh

> Hi,
>
[quoted text clipped - 7 lines]
> cross post instead of multipost, otherwise people in one group will not be
> able to see answers that were posted in the other group.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.