当前位置: 首页 > news >正文

青岛网站建设网站制作百度seo关键词排名s

青岛网站建设网站制作,百度seo关键词排名s,做风险代理案源的网站,小微网站建设接单平台最近涉及到读取WINDOWS 系统电脑设备的各种信息,在一些特殊的PE或者简化系统中是没有WMI查询工具的,所以就自己写了个查询大部分WMI属性值的工具,免去了查网站的功夫。涉及到的方法内容就汇总做个总结。 PS:因为工作中软件基本都是我一个人开…

最近涉及到读取WINDOWS 系统电脑设备的各种信息,在一些特殊的PE或者简化系统中是没有WMI查询工具的,所以就自己写了个查询大部分WMI属性值的工具,免去了查网站的功夫。涉及到的方法内容就汇总做个总结。
PS:因为工作中软件基本都是我一个人开发和维护,所以一般就写一堆一个方法,最近看了很多 GitHub上的代码顿时有种写了一堆屎的感觉,啧啧,向诸位大佬学习借鉴

Win32提供程序查询主要代码

      • 初始化COM库
      • 获取IWbemServices实例
      • WQL查询
      • 获取属性名称、类型的另一种写法
      • CIMTYPE 数据类型转换
      • gumbo-parse解析HTML
      • 小工具可执行程序看文章附件资源
      • 源码下载

初始化COM库

void _print_hresult(const char *file, int line, const char *msg, HRESULT hr);
#define PRINT_HRESULT(hr, msg) _print_hresult(__FILE__, __LINE__, msg, hr)
#define IFFAILED_PRINTERROR(hr, msg)  { HRESULT __hr__ = (hr); if ((__hr__ != RPC_E_TOO_LATE) &&FAILED(__hr__)) { PRINT_HRESULT(__hr__, msg); } }static class BLL_CUSTOM_LIBRARY_EXPORT COMThreading {
public:COMThreading() {// Regardless of return value, you must balance each call to// CoInitialize[Ex] with a call to CoUninitialize.HRESULT hres = CoInitializeEx(0, COINIT_APARTMENTTHREADED);IFFAILED_PRINTERROR(hres, "Error on CoInitializeEx");hres =CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_CONNECT,RPC_C_IMP_LEVEL_IMPERSONATE, NULL, 0, NULL);IFFAILED_PRINTERROR(hres, "Error on CoInitializeSecurity");}~COMThreading() {CoUninitialize();}
};

这种初始化COM库的写法真的就很经典,完全不用担心调用后没释放的问题,第一次看到的时候真的觉得大佬真是牛逼。

获取IWbemServices实例

#define PRINT_HRESULT(hr, msg)   WMIOBJ_PRINT_ERROR(QString("%1 : %2").arg(msg).arg(GetError(hr)))
#define IFFAILED_PRINTERROR(hr, msg)  { HRESULT __hr__ = (hr); if ((__hr__ != RPC_E_TOO_LATE) &&FAILED(__hr__)) { PRINT_HRESULT(__hr__, msg); } }HRESULT GetWMIProxy(const CString &objectPath, CComPtr<IWbemServices> &pSvc)
{WMIOBJ_PRINT_INFO("Execution GetWMIProxy...");HRESULT hres;CComPtr<IWbemLocator> pLoc;hres = CoInitializeSecurity(NULL,-1,                          // COM authenticationNULL,                        // Authentication servicesNULL,                        // ReservedRPC_C_AUTHN_LEVEL_DEFAULT,   // Default authenticationRPC_C_IMP_LEVEL_IMPERSONATE, // Default ImpersonationNULL,                        // Authentication infoEOAC_NONE,                   // Additional capabilitiesNULL                         // Reserved);IFFAILED_PRINTERROR(hres, "Error on CoInitializeSecurity.");// Obtain the initial locator to WMIhres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *)&pLoc);IFFAILED_RETURN_RES(hres, "Error on CoCreateInstance.");hres = pLoc->ConnectServer(_bstr_t(objectPath),     // Object path of WMI namespaceNULL,                    // User name. NULL = current userNULL,                    // User password. NULL = current0,                       // Locale. NULL indicates currentNULL,                    // Security flags.0,                       // Authority (for example, Kerberos)0,                       // Context object&pSvc                    // pointer to IWbemServices proxy);IFFAILED_RETURN_RES(hres, "Error on pLoc->ConnectServer.");// Set security levels on the proxyhres = CoSetProxyBlanket(pSvc,                        // Indicates the proxy to setRPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxxRPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxxNULL,                        // Server principal nameRPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxxRPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxxNULL,                        // client identityEOAC_NONE                    // proxy capabilities);IFFAILED_RETURN_RES(hres, "Error on CoSetProxyBlanket.");return hres;
}

硬件方面的命名空间大多是 L"ROOT\CIMV2",宏定义可以这么用我是真的没想到,我以前还是用的简单了,

WQL查询

通过传人WQL查询对应类的所有属性,只做示例,对应参数类型是封装好的,获取返回参数的所有属性,也是有很多种方法。

   void Lib_WmiObject::SQL_WQL(QString WQL)
{QueryTitle title;QueryData Data;WMIOBJ_PRINT_INFO("Execution Select WQL...<b>START</b>");COMThreading();HRESULT hres;CComPtr<IWbemServices> pSvc;IFFAILED_RETURN(GetWMIProxy(WMI_NAMESPACE, pSvc), " Lib_WmiQuery : Couldn't get WMI proxy");WMIOBJ_PRINT_INFO("WQL : "+WQL);CComPtr<IEnumWbemClassObject> pEnumerator;hres = pSvc->ExecQuery(bstr_t(L"WQL"),bstr_t(WQL.toStdWString().c_str()),WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumerator);IFFAILED_RETURN(hres, "WQL ["+WQL+"] Execution failure.");if(!pEnumerator)WMIOBJ_PRINT_ERROR("WQL 执行失败:"+QString(GetError()));while (pEnumerator){CComPtr<IWbemClassObject> pclsObj;ULONG uReturn = 0;HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);if(0 == uReturn || pclsObj == NULL){if(hr!=ERROR_INVALID_FUNCTION)WMIOBJ_PRINT_ERROR("WQL 执行失败:"+QString(GetError(hr)));break;}if(title.count()==0){SAFEARRAY* pNames;hres=pclsObj->GetNames(L"",WBEM_FLAG_ALWAYS,NULL,&pNames);if (FAILED(hres)){WMIOBJ_PRINT_ERROR("获取属性名称列表失败!");break;}qDebug()<<"lLbound : "<<pNames->cDims;qDebug()<<"cbElements : "<<pNames->cbElements;BSTR HUGEP *pbstr;// Get a pointer to the elements of the array.hr = SafeArrayAccessData(pNames, (void HUGEP**)&pbstr);if (FAILED(hr))continue;for (int i = 0; i < pNames->rgsabound->cElements; i++){BSTR bstrTemp = pbstr[i];title.append(QString::fromWCharArray(bstrTemp));}SafeArrayDestroy(pNames);}QStringList _Data;foreach (QString name , title) {VARIANT vtProp;CIMTYPE  pType= CIM_EMPTY;VariantInit(&vtProp);hr = pclsObj->Get(name.toStdWString().c_str(), 0, &vtProp, &pType, 0);if(FAILED(hr)){_Data.append("[ERROR]");}else_Data.append(check_vatiant_type(vtProp,pType));VariantClear(&vtProp);}Data.append(_Data);}UnCOMThreading();WMIOBJ_PRINT_INFO("Execution Select WQL...<b>END</b>");emit Out_Data(title,Data);
}

获取属性名称、类型的另一种写法

#define IFFAILED_RETURN_RES2(hr, msg)        { HRESULT __hr__ = (hr); if (FAILED(__hr__)) { PRINT_HRESULT(__hr__, msg); return __hr__; } }
HRESULT EnumerateProperties(IWbemClassObject * pObject)
{BSTR name;VARIANT val;CIMTYPE type;LONG flavor;IFFAILED_RETURN_RES2(pObject->BeginEnumeration(WBEM_FLAG_NONSYSTEM_ONLY), "BeginEnumeration");qDebug("Properties:");while (pObject->Next(0, &name, &val, &type, &flavor) != WBEM_S_NO_MORE_DATA) {qDebug("%-20ls type=0x%04x val.vt=0x%04x val:%s", name, type, val.vt,check_vatiant_type(val,type).toStdString().c_str());SysFreeString(name);VariantClear(&val);}return S_OK;
}

CIMTYPE 数据类型转换

之前在GitHub上看到过一个VARIANT数据类型转换的,结果忘了保存下来,自己又不想写,GitHub又打不开,所以只有用CIMTYPE 类型转换成QString

QString Lib_WmiObject::check_vatiant_type(VARIANT Value,CIMTYPE _enum_type)
{if(Value.vt==VT_NULL)return "[NULL]";switch ( _enum_type ){case CIM_ILLEGAL ://值: 0xfff非法值。return QString::fromWCharArray(Value.bstrVal);case CIM_EMPTY : //值: 0 空 (null) 值。return "[NULL]";case CIM_SINT8 : //值: 16//8 位有符号整数。return  QString::number(Value.iVal);case CIM_SINT16 : //值: 2//16 位带符号整数。return  QString::number(Value.iVal);case CIM_SINT32 : //值: 3//32 位带符号整数。return  QString::number(Value.intVal);case CIM_SINT64 : //值: 20//64 位带符号整数。return  QString::number(Value.llVal,10);case CIM_UINT8 : //值: 17//8 位无符号整数。return  QString::number(Value.uiVal);case CIM_UINT16 : //值: 18//16 位无符号整数。return  QString::number(Value.uintVal);case CIM_UINT32 : //值: 19//32 位无符号整数。return  QString::number(Value.uintVal);case CIM_UINT64 : //值: 21//64 位无符号整数。return  QString::number(Value.ullVal,10);case CIM_REAL32 : //值: 4//32 位实数。return  QString::number(Value.intVal);case CIM_REAL64 : //值: 5//64 位实数。return  QString::number(Value.ullVal,10);case CIM_BOOLEAN : //值: 11//一个布尔值。return Value.boolVal?"TRUE":"FALSE";case CIM_STRING : // 值: 8// 字符串值。return QString::fromWCharArray(Value.bstrVal);case CIM_DATETIME : //值: 101//一个日期时间值。case CIM_REFERENCE : //值: 102//另一个对象的引用 (__Path) 。case CIM_CHAR16 : //值: 103//16 位字符值。case CIM_OBJECT : //值: 13//Object 值 。case CIM_FLAG_ARRAY : // 值: 0x2000//数组值。return QString::fromWCharArray(Value.bstrVal);default:return QString::fromWCharArray(Value.bstrVal);}
}

gumbo-parse解析HTML

gumbo-parse用来解析html还行。不确定是不是我方法没写对,我之前尝试过用gumbo-parse解析XML,获取不到节点,最后还是用的QT自带的XML解析工具。

 * https://blog.csdn.net/chijingjing/article/details/104255763#pragma once
#include "stdafx.h"#include "enumtest.cpp"#include "gumbo-parser/Selector.h"#include "gumbo-parser/Document.h"
#include "gumbo-parser/Selection.h"
#include "gumbo-parser/Node.h"void test_parser() {std::string page("<h1><a>wrong link</a><a class=\"special\"\\>some link</a></h1>");CDocument doc;doc.parse(page.c_str());CSelection c = doc.find("h1 a.special");CNode node = c.nodeAt(0);printf("Node: %s\n", node.text().c_str());std::string content = page.substr(node.startPos(), node.endPos() - node.startPos());printf("Node: %s\n", content.c_str());}void test_html() {std::string page = "<html><div><span>1\n</span>2\n</div></html>";CDocument doc;doc.parse(page.c_str());CNode pNode = doc.find("div").nodeAt(0);std::string content = page.substr(pNode.startPos(), pNode.endPos() - pNode.startPos());printf("Node: #%s#\n", content.c_str());
}void test_escape() {std::string page = "<html><div><span id=\"that's\">1\n</span>2\n</div></html>";CDocument doc;doc.parse(page.c_str());CNode pNode = doc.find("span[id=\"that's\"]").nodeAt(0);std::string content = page.substr(pNode.startPos(), pNode.endPos() - pNode.startPos());printf("Node: #%s#\n", content.c_str());
}int main() {test_parser();test_html();test_escape();
}
————————————————
版权声明:本文为CSDN博主「cejutue」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/chijingjing/article/details/104255763

小工具可执行程序看文章附件资源

在这里插入图片描述
在这里插入图片描述

源码下载

Qt开发项目案例-以及部分示例的源码下载链接


文章转载自:
http://zoologically.xxhc.cn
http://inadequateness.xxhc.cn
http://confabulation.xxhc.cn
http://swabber.xxhc.cn
http://reifier.xxhc.cn
http://tideless.xxhc.cn
http://octonary.xxhc.cn
http://skyline.xxhc.cn
http://hereditament.xxhc.cn
http://enwreathe.xxhc.cn
http://scutate.xxhc.cn
http://unstained.xxhc.cn
http://nitrolim.xxhc.cn
http://digram.xxhc.cn
http://hainan.xxhc.cn
http://xanthogenate.xxhc.cn
http://hotch.xxhc.cn
http://illite.xxhc.cn
http://bacillin.xxhc.cn
http://hermaphrodism.xxhc.cn
http://granddam.xxhc.cn
http://angwantibo.xxhc.cn
http://obadiah.xxhc.cn
http://cystotomy.xxhc.cn
http://athanasian.xxhc.cn
http://roundlet.xxhc.cn
http://holp.xxhc.cn
http://baykal.xxhc.cn
http://desmolysis.xxhc.cn
http://quokka.xxhc.cn
http://hin.xxhc.cn
http://vida.xxhc.cn
http://extension.xxhc.cn
http://wimple.xxhc.cn
http://interfering.xxhc.cn
http://armoury.xxhc.cn
http://chancre.xxhc.cn
http://scarey.xxhc.cn
http://odm.xxhc.cn
http://triquetrous.xxhc.cn
http://harquebusier.xxhc.cn
http://friction.xxhc.cn
http://plumulaceous.xxhc.cn
http://unfamiliar.xxhc.cn
http://romantic.xxhc.cn
http://abyssal.xxhc.cn
http://wayleave.xxhc.cn
http://oligochrome.xxhc.cn
http://paratransit.xxhc.cn
http://deducible.xxhc.cn
http://saturant.xxhc.cn
http://diastema.xxhc.cn
http://fica.xxhc.cn
http://sedentariness.xxhc.cn
http://unaccountably.xxhc.cn
http://redemonstrate.xxhc.cn
http://abracadabra.xxhc.cn
http://concision.xxhc.cn
http://bottleneck.xxhc.cn
http://oral.xxhc.cn
http://octan.xxhc.cn
http://adamic.xxhc.cn
http://monotropy.xxhc.cn
http://redowa.xxhc.cn
http://penninite.xxhc.cn
http://massif.xxhc.cn
http://conjunctional.xxhc.cn
http://athlete.xxhc.cn
http://ex.xxhc.cn
http://polygala.xxhc.cn
http://drugola.xxhc.cn
http://seabed.xxhc.cn
http://gabardine.xxhc.cn
http://chitterlings.xxhc.cn
http://payola.xxhc.cn
http://skycap.xxhc.cn
http://buryat.xxhc.cn
http://infusorian.xxhc.cn
http://immobilism.xxhc.cn
http://tuatara.xxhc.cn
http://featheredged.xxhc.cn
http://kymri.xxhc.cn
http://gelable.xxhc.cn
http://paraplasm.xxhc.cn
http://slyly.xxhc.cn
http://mid.xxhc.cn
http://echinoderm.xxhc.cn
http://yankeeism.xxhc.cn
http://ketol.xxhc.cn
http://agamogenesis.xxhc.cn
http://repower.xxhc.cn
http://pipkin.xxhc.cn
http://antimatter.xxhc.cn
http://rhodinal.xxhc.cn
http://hent.xxhc.cn
http://limpa.xxhc.cn
http://unprecedented.xxhc.cn
http://euphobia.xxhc.cn
http://escarpmetnt.xxhc.cn
http://laocoon.xxhc.cn
http://www.dt0577.cn/news/81759.html

相关文章:

  • 做网站思想培训公司
  • asp动态网站设计模板企业宣传网站
  • 网站设计品网站收录平台
  • 政府网站建设人员组成腾讯广告推广平台
  • 公司做企业网站的必要性seo系统培训哪家好
  • 自己做网站开发如何找客户百度seo排名优化公司
  • 带货视频怎么制作教程网站关键词如何优化上首页
  • 网站如何优化排名词爱站的关键词
  • 免费网站建设入门一键制作免费网站的app
  • 邢台网站制作哪里有外贸seo推广公司
  • 全网营销推广网站建设正规接单赚佣金的平台
  • 三只松鼠网络营销策划书seo推广教学
  • 网站建设品牌好西安网站设计公司
  • 廊坊做网站哪家好湘潭网站设计
  • 珠海网站制作价格线上运营的5个步骤
  • 个人网站建设与实现毕业设计百度竞价排名收费
  • 青海专业网站建设推广平台建设网络营销常用的工具和方法
  • wordpress 提问360优化大师官方下载手机
  • 做动态网站用哪个程序软件比较简单?广告联盟哪个比较好
  • 网站的备案怎么处理软文的概念是什么
  • 北京网站设计公司招聘信息产品运营推广方案
  • 网站首页模板代写文章质量高的平台
  • 朝阳网站建设是什么外贸独立站怎么建站
  • 韶关专业网站建设教程微博上如何做网站推广
  • 做网站如何挣钱推广软件下载
  • 中国菲律宾友谊淘宝seo搜索优化
  • 网站被做暗链报告免费网络推广平台有哪些
  • 做网站必须要有的素材贵州二级站seo整站优化排名
  • 免费软件下载网站app品牌推广策划方案案例
  • 整页型网站微信如何引流推广精准加人