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
b657c6e8
Commit
b657c6e8
authored
Sep 30, 2019
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update device unique identifire
parent
bef40403
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
155 additions
and
409 deletions
+155
-409
DeviceUniqueIdentifierHeaderOnly.h
jlib/win32/DeviceUniqueIdentifierHeaderOnly.h
+95
-346
wmi.h
jlib/win32/wmi.h
+60
-63
No files found.
jlib/win32/DeviceUniqueIdentifierHeaderOnly.h
View file @
b657c6e8
This diff is collapsed.
Click to expand it.
jlib/win32/wmi.h
View file @
b657c6e8
...
...
@@ -29,8 +29,6 @@ typedef std::function<void(const std::wstring&, const std::wstring&)> OutputFunc
class
WmiBase
{
public
:
WmiBase
(
const
std
::
wstring
&
_namespace
,
OutputFunc
outputFunc
,
ErrorFunc
errorFunc
=
nullptr
)
:
namespace_
(
_namespace
)
,
outputFunc_
(
outputFunc
)
...
...
@@ -100,7 +98,65 @@ public:
}
while
(
0
);
return
hr
;
return
!
FAILED
(
hr
);
}
protected
:
bool
initCom
(
HRESULT
&
hr
)
{
hr
=
CoInitializeEx
(
NULL
,
COINIT_MULTITHREADED
);
if
(
FAILED
(
hr
))
{
if
(
hr
==
0x80010106
)
{
// already initilized, pass
}
else
{
hr
=
CoInitializeEx
(
NULL
,
COINIT_APARTMENTTHREADED
);
if
(
FAILED
(
hr
))
{
return
false
;
}
}
}
return
true
;
}
HRESULT
setComSecurityLevel
()
{
return
CoInitializeSecurity
(
NULL
,
-
1
,
NULL
,
NULL
,
RPC_C_AUTHN_LEVEL_DEFAULT
,
RPC_C_IMP_LEVEL_IMPERSONATE
,
NULL
,
EOAC_NONE
,
NULL
);
}
HRESULT
obtainWbemLocator
(
CComPtr
<
IWbemLocator
>&
locator
)
{
return
CoCreateInstance
(
CLSID_WbemLocator
,
0
,
CLSCTX_INPROC_SERVER
,
IID_IWbemLocator
,
(
LPVOID
*
)
&
locator
);
}
HRESULT
connect
(
CComPtr
<
IWbemLocator
>
locator
,
CComPtr
<
IWbemServices
>&
services
)
{
return
locator
->
ConnectServer
(
CComBSTR
(
namespace_
.
data
()),
NULL
,
NULL
,
NULL
,
0
,
NULL
,
NULL
,
&
services
);
}
HRESULT
setProxySecurityLevel
(
CComPtr
<
IWbemServices
>
services
)
{
return
CoSetProxyBlanket
(
services
,
// Indicates the proxy to set
RPC_C_AUTHN_WINNT
,
// RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE
,
// RPC_C_AUTHZ_xxx
NULL
,
// Server principal name
RPC_C_AUTHN_LEVEL_CALL
,
// RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE
,
// RPC_C_IMP_LEVEL_xxx
NULL
,
// client identity
EOAC_NONE
// proxy capabilities
);
}
HRESULT
parseIWbemClassObject
(
CComPtr
<
IWbemClassObject
>
object
)
{
...
...
@@ -145,7 +201,7 @@ public:
switch
(
value
.
vt
)
{
case
VT_BSTR
:
Value
=
value
.
bstrVal
;
Value
=
value
.
bstrVal
;
break
;
case
VT_I1
:
...
...
@@ -201,65 +257,6 @@ public:
return
WBEM_S_NO_ERROR
;
}
protected
:
bool
initCom
(
HRESULT
&
hr
)
{
hr
=
CoInitializeEx
(
NULL
,
COINIT_MULTITHREADED
);
if
(
FAILED
(
hr
))
{
if
(
hr
==
0x80010106
)
{
// already initilized, pass
}
else
{
hr
=
CoInitializeEx
(
NULL
,
COINIT_APARTMENTTHREADED
);
if
(
FAILED
(
hr
))
{
return
false
;
}
}
}
return
true
;
}
HRESULT
setComSecurityLevel
()
{
return
CoInitializeSecurity
(
NULL
,
-
1
,
NULL
,
NULL
,
RPC_C_AUTHN_LEVEL_DEFAULT
,
RPC_C_IMP_LEVEL_IMPERSONATE
,
NULL
,
EOAC_NONE
,
NULL
);
}
HRESULT
obtainWbemLocator
(
CComPtr
<
IWbemLocator
>&
locator
)
{
return
CoCreateInstance
(
CLSID_WbemLocator
,
0
,
CLSCTX_INPROC_SERVER
,
IID_IWbemLocator
,
(
LPVOID
*
)
&
locator
);
}
HRESULT
connect
(
CComPtr
<
IWbemLocator
>
locator
,
CComPtr
<
IWbemServices
>&
services
)
{
return
locator
->
ConnectServer
(
CComBSTR
(
namespace_
.
data
()),
NULL
,
NULL
,
NULL
,
0
,
NULL
,
NULL
,
&
services
);
}
HRESULT
setProxySecurityLevel
(
CComPtr
<
IWbemServices
>
services
)
{
return
CoSetProxyBlanket
(
services
,
// Indicates the proxy to set
RPC_C_AUTHN_WINNT
,
// RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE
,
// RPC_C_AUTHZ_xxx
NULL
,
// Server principal name
RPC_C_AUTHN_LEVEL_CALL
,
// RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE
,
// RPC_C_IMP_LEVEL_xxx
NULL
,
// client identity
EOAC_NONE
// proxy capabilities
);
}
protected
:
std
::
wstring
namespace_
=
{};
CComPtr
<
IWbemServices
>
services_
=
{};
...
...
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