 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Luke Andy Guest
|
Posted: Sun Aug 07, 2005 4:46 pm Post subject: sourecode in BCB6 showing how to use WMI in WinXP |
|
|
Is there any *.cpp sourecode in BCB6 showing how to use WMI in WinXP?
I'm particularly looking solution for use "Ndis80211ReceivedSignalStrength"
in WMI.
From
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/using_wmi.asp
Platform SDK: Windows Management Instrumentation
Using WMI
WMI can be used to obtain data about your hardware and software from WMI by
writing a client script or application, and provide data from hardware or
software operations to WMI by creating a WMI provider.
....
|
|
| Back to top |
|
 |
Ed Mulroy Guest
|
Posted: Sun Aug 07, 2005 6:17 pm Post subject: Re: sourecode in BCB6 showing how to use WMI in WinXP |
|
|
You might try converting the code at this link:
http://www.vbip.com/wininet/wininet_connection_01.asp
WMI is huge. It would difficult to create the kind of simple code one wants
in an example yet exercise a decent percentage of it. You would probably be
best served by getting a book that deals with WMI.
.. Ed
| Quote: | Luke Andy wrote in message
news:42f63ae8$1 (AT) newsgroups (DOT) borland.com...
Is there any *.cpp sourecode in BCB6 showing how to use WMI in WinXP? I'm
particularly looking solution for use "Ndis80211ReceivedSignalStrength" in
WMI.
From
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/using_wmi.asp
Platform SDK: Windows Management Instrumentation
Using WMI
WMI can be used to obtain data about your hardware and software from WMI
by writing a client script or application, and provide data from hardware
or software operations to WMI by creating a WMI provider.
|
|
|
| Back to top |
|
 |
Luke Andy Guest
|
Posted: Mon Aug 08, 2005 9:49 am Post subject: Re: sourecode in BCB6 showing how to use WMI in WinXP |
|
|
| Quote: | You might try converting the code at this link:
http://www.vbip.com/wininet/wininet_connection_01.asp
WMI is huge. It would difficult to create the kind of simple code one
wants in an example yet exercise a decent percentage of it. You would
probably be best served by getting a book that deals with WMI.
. Ed
|
Thank you for the link. I also found the following very short VB6 code, but
it seems to be that it is not that simple to convert it to C++ for BCB6.
Private Sub Timer1_Timer()
Set nicset =
GetObject("winmgmts:{impersonationLevel=impersonate}!root/wmi").InstancesOf("MSNdis_80211_ReceivedSignalStrength")
On Error GoTo no80211Error
For Each nic In nicset
SignalStrengthValue = Right(nic.Ndis80211ReceivedSignalStrength,
Len(nic.Ndis80211ReceivedSignalStrength) - 1)
If SignalStrengthValue <> "" Then
SendText ("S=NetSignalStrength~" & SignalStrengthValue)
End If
Exit For
Next
nicset = Nothing
Exit Sub
no80211Error:
SendToConsole "No 802.11 network adapters found"
Timer1.Enabled = False
End Sub
|
|
| Back to top |
|
 |
tinyabs Guest
|
Posted: Mon Aug 08, 2005 10:27 am Post subject: Re: sourecode in BCB6 showing how to use WMI in WinXP |
|
|
#include <vcl.h>
#include <ole2.h>
#include <iostream.h>
#include <conio.h>
#include <Wbemidl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma link "Wbemuuid.lib"
#pragma argsused
void GetWmiInfo(TStrings *lpList, WideString wsClass)
{
IWbemLocator *pWbemLocator = NULL;
if(CoCreateInstance(CLSID_WbemAdministrativeLocator, NULL,
CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, IID_IUnknown,
(void**)&pWbemLocator) == S_OK)
{
IWbemServices *pWbemServices = NULL;
WideString wsNamespace = (L"root\cimv2");
if(pWbemLocator->ConnectServer(wsNamespace, NULL, NULL, NULL, 0, NULL,
NULL, &pWbemServices) == S_OK)
{
IEnumWbemClassObject *pEnumClassObject = NULL;
WideString wsWQL=L"WQL", wsQuery=WideString(L"Select * from
")+wsClass;
if(pWbemServices->ExecQuery(wsWQL, wsQuery,
WBEM_FLAG_RETURN_IMMEDIATELY,NULL, &pEnumClassObject) == S_OK)
{
IWbemClassObject *pClassObject = NULL;
ULONG uCount = 1, uReturned;
if(pEnumClassObject->Reset() == S_OK)
{
int iEnumIdx = 0;
while(pEnumClassObject->Next(WBEM_INFINITE, uCount,
&pClassObject, &uReturned) == S_OK)
{
lpList->Add("----------------
["+IntToStr(iEnumIdx)+"] -----------------");
SAFEARRAY *pvNames = NULL;
if(pClassObject->GetNames(NULL, WBEM_FLAG_ALWAYS |
WBEM_MASK_CONDITION_ORIGIN, NULL, &pvNames) == S_OK)
{
long vbl, vbu;
SafeArrayGetLBound(pvNames, 1, &vbl);
SafeArrayGetUBound(pvNames, 1, &vbu);
for(long idx=vbl; idx<=vbu; idx++)
{
long aidx = idx;
wchar_t *wsName = 0;
VARIANT vValue;
VariantInit(&vValue);
SafeArrayGetElement(pvNames, &aidx, &wsName);
BSTR bs = SysAllocString(wsName);
HRESULT hRes = pClassObject->Get(bs, 0, &vValue,
NULL, 0);
SysFreeString(bs);
if(hRes == S_OK)
{
AnsiString s;
Variant v = *(Variant*)&vValue;
if(v.IsArray())
{
for(int i=v.ArrayLowBound();
i<=v.ArrayHighBound(); i++)
{
Variant a = v.GetElement(i);
if(!s.IsEmpty())
s+=", ";
s+=VarToStr(a);
}
}
else
{
s = VarToStr(v);
}
lpList->Add(AnsiString(wsName)+"="+s);
}
VariantClear(&vValue);
SysFreeString(wsName);
}
}
if(pvNames)SafeArrayDestroy(pvNames);
iEnumIdx++;
}
}
if(pClassObject)pClassObject->Release();
}
if(pEnumClassObject)pEnumClassObject->Release();
}
if(pWbemServices)pWbemServices->Release();
}
if(pWbemLocator)pWbemLocator->Release();
}
int main(int argc, char* argv[])
{
CoInitializeEx(0, COINIT_MULTITHREADED);
CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_CONNECT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, EOAC_NONE, 0
);
TStringList *list = new TStringList();
GetWmiInfo(list, "Win32_Processor");
for (int i = 0; i < list->Count; i++)
{
cout << list->Strings[i].c_str() << endl;
}
CoUninitialize();
getch();
return 0;
}
|
|
| Back to top |
|
 |
Luke Andy Guest
|
Posted: Mon Aug 08, 2005 11:50 am Post subject: Re: sourecode in BCB6 showing how to use WMI in WinXP |
|
|
Dear "tinyabs",
Thank you very much for the source code.
Am I supposed to install some special library etc to my WinXP inorder to
have the "Wbemuuid.lib" ?
Once again, THANK YOU!.
Luke
| Quote: |
#include <vcl.h
#include
#include
#include
#include
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma link "Wbemuuid.lib"
#pragma argsused
void GetWmiInfo(TStrings *lpList, WideString wsClass)
{
IWbemLocator *pWbemLocator = NULL;
if(CoCreateInstance(CLSID_WbemAdministrativeLocator, NULL,
CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, IID_IUnknown,
(void**)&pWbemLocator) == S_OK)
{
IWbemServices *pWbemServices = NULL;
WideString wsNamespace = (L"root\cimv2");
if(pWbemLocator->ConnectServer(wsNamespace, NULL, NULL, NULL, 0, NULL,
NULL, &pWbemServices) == S_OK)
{
IEnumWbemClassObject *pEnumClassObject = NULL;
WideString wsWQL=L"WQL", wsQuery=WideString(L"Select * from
")+wsClass;
if(pWbemServices->ExecQuery(wsWQL, wsQuery,
WBEM_FLAG_RETURN_IMMEDIATELY,NULL, &pEnumClassObject) == S_OK)
{
IWbemClassObject *pClassObject = NULL;
ULONG uCount = 1, uReturned;
if(pEnumClassObject->Reset() == S_OK)
{
int iEnumIdx = 0;
while(pEnumClassObject->Next(WBEM_INFINITE, uCount,
&pClassObject, &uReturned) == S_OK)
{
lpList->Add("----------------
["+IntToStr(iEnumIdx)+"] -----------------");
SAFEARRAY *pvNames = NULL;
if(pClassObject->GetNames(NULL, WBEM_FLAG_ALWAYS |
WBEM_MASK_CONDITION_ORIGIN, NULL, &pvNames) == S_OK)
{
long vbl, vbu;
SafeArrayGetLBound(pvNames, 1, &vbl);
SafeArrayGetUBound(pvNames, 1, &vbu);
for(long idx=vbl; idx<=vbu; idx++)
{
long aidx = idx;
wchar_t *wsName = 0;
VARIANT vValue;
VariantInit(&vValue);
SafeArrayGetElement(pvNames, &aidx, &wsName);
BSTR bs = SysAllocString(wsName);
HRESULT hRes = pClassObject->Get(bs, 0, &vValue,
NULL, 0);
SysFreeString(bs);
if(hRes == S_OK)
{
AnsiString s;
Variant v = *(Variant*)&vValue;
if(v.IsArray())
{
for(int i=v.ArrayLowBound();
i<=v.ArrayHighBound(); i++)
{
Variant a = v.GetElement(i);
if(!s.IsEmpty())
s+=", ";
s+=VarToStr(a);
}
}
else
{
s = VarToStr(v);
}
lpList->Add(AnsiString(wsName)+"="+s);
}
VariantClear(&vValue);
SysFreeString(wsName);
}
}
if(pvNames)SafeArrayDestroy(pvNames);
iEnumIdx++;
}
}
if(pClassObject)pClassObject->Release();
}
if(pEnumClassObject)pEnumClassObject->Release();
}
if(pWbemServices)pWbemServices->Release();
}
if(pWbemLocator)pWbemLocator->Release();
}
int main(int argc, char* argv[])
{
CoInitializeEx(0, COINIT_MULTITHREADED);
CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_CONNECT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, EOAC_NONE, 0
);
TStringList *list = new TStringList();
GetWmiInfo(list, "Win32_Processor");
for (int i = 0; i < list->Count; i++)
{
cout << list->Strings[i].c_str() << endl;
}
CoUninitialize();
getch();
return 0;
}
|
|
|
| Back to top |
|
 |
tinyabs Guest
|
|
| Back to top |
|
 |
Darko Miletic Guest
|
Posted: Sat Aug 13, 2005 12:54 pm Post subject: Re: sourecode in BCB6 showing how to use WMI in WinXP |
|
|
Luke Andy wrote:
| Quote: | Dear "tinyabs",
Thank you very much for the source code.
Am I supposed to install some special library etc to my WinXP inorder to
have the "Wbemuuid.lib" ?
Once again, THANK YOU!.
Luke
|
You can get it from here http://makefiles.lebeausoftware.org/
Darko
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|