Monthly Archives: July 2014

如何使用C++调用WMI实例的方法

WMI接口对于C++来说十分不友好,包括文档,对于实例对象,通常可以通过WQL查询获得查询对象的实例, 比如: hr = pSvc->ExecQuery(bstr_t(“WQL”), bstr_t(“SELECT * FROM Win32_Service”),                    WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,                    NULL,&pEnumerator); 可以获取系统服务对象的集合,通过pEnumerator可以获得所有服务的实例,通过实例通过Get方法获得属性是容易的,对应的sample在网上也很多.但是涉及到通过某个具体的实例调用class的方法,却没有什么sample.看起来微软故意隐藏了这个方面的实现细节.最近终于找到一篇文章描述如何透过WMI实例调用class方法,最根本的地方是要通过实例对象,获取instance class名字,作为IWbemServices::ExecMethod 的第一个参数strOjbectPath.以下代码片段是设置service start type的sample, 一看就明白 pSvc->ExecQuery(bstr_t(“WQL”), bstr_t(“SELECT * FROM Win32_Service”), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); while(pEnumerator) { pEnumerator->Next(WBEM_INFINITE, … Continue reading

Posted in tech | Tagged , , , , | Leave a comment

How to connect iscsi target with special IP address(NIC) in C C++

i don’t know where goes my context!! No draft, no reversion, Oh no no. I don’t want to write tooo much, just make it simple: to connect to a iscsi target using special portal number (mapping to special host ip) … Continue reading

Posted in tech | Tagged | Leave a comment