Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
jlib
Commits
ddaf585e
Commit
ddaf585e
authored
Nov 30, 2018
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
2346735a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
10 deletions
+18
-10
DeviceUniqueIdentifierHeaderOnly.h
jlib/win32/DeviceUniqueIdentifierHeaderOnly.h
+18
-10
No files found.
jlib/win32/DeviceUniqueIdentifierHeaderOnly.h
View file @
ddaf585e
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment