Commit ddaf585e authored by captainwong's avatar captainwong

fix

parent 2346735a
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <unordered_map>
#include <Windows.h> #include <Windows.h>
#include <winioctl.h> #include <winioctl.h>
...@@ -120,7 +121,7 @@ enum { ...@@ -120,7 +121,7 @@ enum {
* @param[in,out] results 查询结果集合 * @param[in,out] results 查询结果集合
* @return 成功或失败 * @return 成功或失败
*/ */
static bool query(size_t queryTypes, std::vector<std::wstring>& results); static bool query(size_t queryTypes, std::unordered_map<QueryType, std::wstring>& results);
/** /**
* @brief 查询信息 * @brief 查询信息
...@@ -128,7 +129,7 @@ static bool query(size_t queryTypes, std::vector<std::wstring>& results); ...@@ -128,7 +129,7 @@ static bool query(size_t queryTypes, std::vector<std::wstring>& results);
* @param[in,out] results 查询结果集合 * @param[in,out] results 查询结果集合
* @return 成功或失败 * @return 成功或失败
*/ */
static bool query(const std::vector<QueryType>& queryTypes, std::vector<std::wstring>& results); static bool query(const std::vector<QueryType>& queryTypes, std::unordered_map<QueryType, std::wstring>& results);
/** /**
* @brief 连接查询结果为一个字符串 * @brief 连接查询结果为一个字符串
...@@ -383,7 +384,9 @@ static std::wstring getMachineGUID() ...@@ -383,7 +384,9 @@ static std::wstring getMachineGUID()
RegCloseKey(hKey); RegCloseKey(hKey);
throw "Could not read registry value"; throw "Could not read registry value";
} }
if (value.back() == L'\0') {
value.erase(value.size() - 1, 1);
}
res = value; res = value;
RegCloseKey(hKey); RegCloseKey(hKey);
...@@ -396,7 +399,7 @@ static std::wstring getMachineGUID() ...@@ -396,7 +399,7 @@ static std::wstring getMachineGUID()
} // end of namespace detail } // end of namespace detail
static bool query(size_t queryTypes, std::vector<std::wstring>& results) static bool query(size_t queryTypes, std::unordered_map<QueryType, std::wstring>& results)
{ {
std::vector<QueryType> vec; std::vector<QueryType> vec;
...@@ -427,14 +430,14 @@ static bool query(size_t queryTypes, std::vector<std::wstring>& results) ...@@ -427,14 +430,14 @@ static bool query(size_t queryTypes, std::vector<std::wstring>& results)
auto ok = query(vec, results); auto ok = query(vec, results);
if (queryTypes & WINDOWS_MACHINE_GUID) { if (queryTypes & WINDOWS_MACHINE_GUID) {
results.push_back(detail::getMachineGUID()); results[WINDOWS_MACHINE_GUID] = (detail::getMachineGUID());
} }
return ok; return ok;
} }
// 基于Windows Management Instrumentation(Windows管理规范) // 基于Windows Management Instrumentation(Windows管理规范)
static bool query(const std::vector<QueryType>& queryTypes, std::vector<std::wstring>& results) static bool query(const std::vector<QueryType>& queryTypes, std::unordered_map<QueryType, std::wstring>& results)
{ {
bool ok = false; bool ok = false;
...@@ -514,6 +517,11 @@ static bool query(const std::vector<QueryType>& queryTypes, std::vector<std::wst ...@@ -514,6 +517,11 @@ static bool query(const std::vector<QueryType>& queryTypes, std::vector<std::wst
} }
for (auto queryType : queryTypes) { for (auto queryType : queryTypes) {
if (queryType == WINDOWS_MACHINE_GUID) {
results[WINDOWS_MACHINE_GUID] = (detail::getMachineGUID());
continue;
}
auto query = detail::getWQLQuery(queryType); auto query = detail::getWQLQuery(queryType);
// 通过请求代理来向WMI发送请求 // 通过请求代理来向WMI发送请求
...@@ -526,9 +534,9 @@ static bool query(const std::vector<QueryType>& queryTypes, std::vector<std::wst ...@@ -526,9 +534,9 @@ static bool query(const std::vector<QueryType>& queryTypes, std::vector<std::wst
&pEnumerator &pEnumerator
); );
if (FAILED(hres)) { if (FAILED(hres)) {
pSvc->Release(); //pSvc->Release();
pLoc->Release(); //pLoc->Release();
CoUninitialize(); //CoUninitialize();
continue; continue;
} }
...@@ -558,7 +566,7 @@ static bool query(const std::vector<QueryType>& queryTypes, std::vector<std::wst ...@@ -558,7 +566,7 @@ static bool query(const std::vector<QueryType>& queryTypes, std::vector<std::wst
VariantClear(&vtProperty); VariantClear(&vtProperty);
// 对属性值做进一步的处理 // 对属性值做进一步的处理
if (detail::WMI_DoWithProperty(queryType, deviceProperty.szProperty, detail::DeviceProperty::PROPERTY_MAX_LEN)) { if (detail::WMI_DoWithProperty(queryType, deviceProperty.szProperty, detail::DeviceProperty::PROPERTY_MAX_LEN)) {
results.push_back(deviceProperty.szProperty); results[queryType] = (deviceProperty.szProperty);
ok = true; ok = true;
pclsObj->Release(); pclsObj->Release();
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment