本文整理汇总了C++中IEnumWbemClassObject::Reset方法的典型用法代码示例。如果您正苦于以下问题:C++ IEnumWbemClassObject::Reset方法的具体用法?C++ IEnumWbemClassObject::Reset怎么用?C++ IEnumWbemClassObject::Reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumWbemClassObject
的用法示例。
在下文中一共展示了IEnumWbemClassObject::Reset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetVideoMemoryViaWMI
HRESULT GetVideoMemoryViaWMI( WCHAR* strInputDeviceID, DWORD* pdwAdapterRam )
{
HRESULT hr;
bool bGotMemory = false;
HRESULT hrCoInitialize = S_OK;
IWbemLocator* pIWbemLocator = nullptr;
IWbemServices* pIWbemServices = nullptr;
BSTR pNamespace = nullptr;
*pdwAdapterRam = 0;
hrCoInitialize = CoInitialize( 0 );
hr = CoCreateInstance( CLSID_WbemLocator,
nullptr,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator,
( LPVOID* )&pIWbemLocator );
#ifdef PRINTF_DEBUGGING
if( FAILED( hr ) ) wprintf( L"WMI: CoCreateInstance failed: 0x%0.8x\n", hr );
#endif
if( SUCCEEDED( hr ) && pIWbemLocator )
{
// Using the locator, connect to WMI in the given namespace.
pNamespace = SysAllocString( L"\\\\.\\root\\cimv2" );
hr = pIWbemLocator->ConnectServer( pNamespace, nullptr, nullptr, 0L,
0L, nullptr, nullptr, &pIWbemServices );
#ifdef PRINTF_DEBUGGING
if( FAILED( hr ) ) wprintf( L"WMI: pIWbemLocator->ConnectServer failed: 0x%0.8x\n", hr );
#endif
if( SUCCEEDED( hr ) && pIWbemServices != 0 )
{
HINSTANCE hinstOle32 = nullptr;
hinstOle32 = LoadLibraryW( L"ole32.dll" );
if( hinstOle32 )
{
PfnCoSetProxyBlanket pfnCoSetProxyBlanket = nullptr;
pfnCoSetProxyBlanket = ( PfnCoSetProxyBlanket )GetProcAddress( hinstOle32, "CoSetProxyBlanket" );
if( pfnCoSetProxyBlanket != 0 )
{
// Switch security level to IMPERSONATE.
pfnCoSetProxyBlanket( pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, nullptr,
RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, 0 );
}
FreeLibrary( hinstOle32 );
}
IEnumWbemClassObject* pEnumVideoControllers = nullptr;
BSTR pClassName = nullptr;
pClassName = SysAllocString( L"Win32_VideoController" );
hr = pIWbemServices->CreateInstanceEnum( pClassName, 0,
nullptr, &pEnumVideoControllers );
#ifdef PRINTF_DEBUGGING
if( FAILED( hr ) ) wprintf( L"WMI: pIWbemServices->CreateInstanceEnum failed: 0x%0.8x\n", hr );
#endif
if( SUCCEEDED( hr ) && pEnumVideoControllers )
{
IWbemClassObject* pVideoControllers[10] = {0};
DWORD uReturned = 0;
BSTR pPropName = nullptr;
// Get the first one in the list
pEnumVideoControllers->Reset();
hr = pEnumVideoControllers->Next( 5000, // timeout in 5 seconds
10, // return the first 10
pVideoControllers,
&uReturned );
#ifdef PRINTF_DEBUGGING
if( FAILED( hr ) ) wprintf( L"WMI: pEnumVideoControllers->Next failed: 0x%0.8x\n", hr );
if( uReturned == 0 ) wprintf( L"WMI: pEnumVideoControllers uReturned == 0\n" );
#endif
VARIANT var;
if( SUCCEEDED( hr ) )
{
bool bFound = false;
for( UINT iController = 0; iController < uReturned; iController++ )
{
if ( !pVideoControllers[iController] )
continue;
pPropName = SysAllocString( L"PNPDeviceID" );
hr = pVideoControllers[iController]->Get( pPropName, 0L, &var, nullptr, nullptr );
#ifdef PRINTF_DEBUGGING
if( FAILED( hr ) )
wprintf( L"WMI: pVideoControllers[iController]->Get PNPDeviceID failed: 0x%0.8x\n", hr );
#endif
if( SUCCEEDED( hr ) )
{
if( wcsstr( var.bstrVal, strInputDeviceID ) != 0 )
bFound = true;
}
VariantClear( &var );
//.........这里部分代码省略.........
示例2: GetWmiInfo
tstring CCliMgr::GetWmiInfo( LPCTSTR lpszClass,LPCTSTR lpszField)
{
tstring SysInfo,strtmp;
HRESULT ret;
ret = CoInitialize(NULL);
ret = CoInitializeSecurity( NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
0
);
if (ret == S_OK || ret== RPC_E_TOO_LATE )
{
IWbemLocator * pIWbemLocator = NULL;
IWbemServices * pWbemServices = NULL;
IEnumWbemClassObject * pEnumObject = NULL;
BSTR bstrNamespace = (L"root\\cimv2");// 通过 IWbemLocator 和 IWbemServices 这两个 COM 接口访问 WMI, 获取系统信息
if(CoCreateInstance (CLSID_WbemAdministrativeLocator, NULL,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown ,(void**)&pIWbemLocator)
== S_OK)
{
if(pIWbemLocator->ConnectServer(
bstrNamespace, // Namespace
NULL, // Userid
NULL, // PW
NULL, // Locale
0, // flags
NULL, // Authority
NULL, // Context
&pWbemServices
) == S_OK)
{
HRESULT hRes;
_bstr_t strQuery = (L"Select * from Win32_OperatingSystem");
hRes = pWbemServices->ExecQuery(_bstr_t("WQL"), strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);
if(hRes == S_OK)
{
ULONG uCount = 1, uReturned;
IWbemClassObject * pClassObject = NULL;
hRes = pEnumObject->Reset();
if(hRes == S_OK)
{
hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject, &uReturned);
if(hRes == S_OK)
{
strtmp = "操作系统的名称: "+_getWmiInfo(pClassObject,"Caption")+"\r\n";
SysInfo = SysInfo + strtmp;
}
if (pClassObject != NULL)
pClassObject->Release();
}
}
strQuery = (L"Select * from Win32_DiskDrive");
hRes = pWbemServices->ExecQuery(_bstr_t("WQL"), strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);
if(hRes == S_OK)
{
ULONG uCount = 1, uReturned;
IWbemClassObject * pClassObject = NULL;
hRes = pEnumObject->Reset();
if(hRes == S_OK)
{
hRes = pEnumObject->Next(WBEM_INFINITE,uCount, &pClassObject, &uReturned);
if(hRes == S_OK)
{
strtmp = "硬盘的Model: "+_getWmiInfo(pClassObject,"Model")+"\r\n";
SysInfo = SysInfo + strtmp;
m_pLogger->WriteLog(LM_INFO, TEXT("硬盘的Model: %s"),_getWmiInfo(pClassObject,"Model").c_str());
}
if (pClassObject != NULL)
pClassObject->Release();
}
}
strQuery = (L"Select * from Win32_LogicalDisk");
hRes = pWbemServices->ExecQuery(_bstr_t("WQL"), strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);
if(hRes == S_OK)
{
ULONG uCount = 1, uReturned;
IWbemClassObject * pClassObject = NULL;
hRes = pEnumObject->Reset();
if(hRes == S_OK)
{
while( pEnumObject->Next( WBEM_INFINITE,
uCount, &pClassObject, &uReturned) == S_OK )
{
if (atoi(_getWmiInfo(pClassObject,"DriveType").c_str()) != 3)
continue;
tstring str;
str =_getWmiInfo(pClassObject,"Name");
strtmp = "盘符: " +str+" ";
m_pLogger->WriteLog(LM_INFO, TEXT("盘符: %s"),str.c_str());
tstring drv;
drv += toupper(str[0]);
if(m_Hy.IsDriverProtected((char *)drv.c_str()))
{
strtmp = strtmp+ "还原状态: 保护 ";
m_pLogger->WriteLog(LM_INFO, TEXT("还原状态: 保护 "));
//.........这里部分代码省略.........
示例3: QueryNetworkAdapters
void QueryNetworkAdapters(std::string query, std::vector<NetworkAdapter*> &vAdapters)
{
std::cout << "1: " << &vAdapters << std::endl;
HRESULT hRes;
// // Step 1: --------------------------------------------------
// // Initialize COM. ------------------------------------------
// hRes = CoInitializeEx(0, COINIT_MULTITHREADED);
// if (FAILED(hRes))
// {
// std::cout << "Failed to initialize COM library. Error code = 0x" << std::hex << hRes << std::endl;
// }
// // Step 2: --------------------------------------------------
// // Set general COM security levels --------------------------
// // Note: If you are using Windows 2000, you need to specify -
// // the default authentication credentials for a user by using
// // a SOLE_AUTHENTICATION_LIST structure in the pAuthList ----
// // parameter of CoInitializeSecurity ------------------------
// hRes = CoInitializeSecurity(
// NULL,
// -1, // COM authentication
// NULL, // Authentication services
// NULL, // Reserved
// RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
// RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
// NULL, // Authentication info
// EOAC_NONE, // Additional capabilities
// NULL // Reserved
// );
//if (FAILED(hRes))
//{
// std::cout << "Failed to initialize security. Error code = 0x" << std::hex << hRes << std::endl;
// CoUninitialize();
//}
IWbemLocator* pIWbemLocator = NULL;
IWbemServices* pWbemServices = NULL;
BSTR bstrNamespace = (L"root\\cimv2");
hRes = CoCreateInstance(
CLSID_WbemAdministrativeLocator,
NULL,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
IID_IUnknown,
(void **)&pIWbemLocator
);
if (SUCCEEDED(hRes))
{
hRes = pIWbemLocator->ConnectServer(
L"root\\cimv2", // Namespace
NULL, // Userid
NULL, // PW
NULL, // Locale
0, // flags
NULL, // Authority
NULL, // Context
&pWbemServices
);
}
// Format query
query = "SELECT * FROM Win32_NetworkAdapter " + query;
BSTR bsQuery = ConvertStringToBSTR(query.c_str());
IEnumWbemClassObject* pEnumrator = NULL;
hRes = pWbemServices->ExecQuery(L"WQL", bsQuery, WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumrator);
if (FAILED(hRes))
{
std::cout << "Failed pWbemServices->ExecQuery. Error code = 0x" << std::hex << hRes << std::endl;
CoUninitialize();
}
IWbemClassObject* pClassObject[128] = {0};
ULONG uReturned;
hRes = pEnumrator->Reset();
hRes = pEnumrator->Next(WBEM_INFINITE, 128, pClassObject, &uReturned);
if (FAILED(hRes))
{
std::cout << "Failed pEnumObject->Next. Error code = 0x" << std::hex << hRes << std::endl;
CoUninitialize();
}
// Fill the vector
for (int i = 0; i < uReturned; i++)
{
_variant_t guid;
pClassObject[i]->Get(L"GUID", 0, &guid, NULL, NULL);
//vNetworkAdapters.push_back(new NetworkAdapter(std::string(_com_util::ConvertBSTRToString(guid.bstrVal))));
if (guid.vt == VT_BSTR)
{
//NetworkAdapter na(std::string(_com_util::ConvertBSTRToString(guid.bstrVal)));
//vAdapters.push_back(new NetworkAdapter("{D15F65F4-27C5-4548-8705-B50B5B360737}"));
char* chBuf = ConvertBSTRToString(guid.bstrVal);
vAdapters.push_back(new NetworkAdapter(std::string(chBuf)));
//.........这里部分代码省略.........