-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.h
61 lines (48 loc) · 1.38 KB
/
library.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @file library.h
* @author Stavros Avramidis
* @date 5/28/2019
* @brief Library bind of WMI with c++
*/
#pragma once
// c++ libs
#include <string>
#include <vector>
#include <map>
#include <regex>
// c libs
#include <comdef.h>
// windows libs
#include <Wbemidl.h>
#include <Windows.h>
#define WMI_WAIT_TIME 2000 /// Max time to wait for next object in when enumerating next object in wmi query in milliseconds
#pragma comment(lib, "wbemuuid.lib")
typedef std::map<std::string, std::string> QueryObj;
typedef std::map<std::string, std::regex> AdditionalFilters;
typedef std::pair<std::string, std::regex> AdditionalFilter;
class Wmi {
/**
* Wmi Base Class
*/
public:
Wmi();
~Wmi();
/**
* @breif Initialises connection to WMI host
* @return HRESULT if any problem occurs
*/
HRESULT init();
/**
* @brief makes a wmi query
* @param queryStr query sting (see https://docs.microsoft.com/en-us/windows/desktop/wmisdk/wql-sql-for-wmi)
* @param queryVectorOut vector of QueryObj to hold results
* @param filters optional pair of filters to be applied to WMi yields
* @return HRESULT if any problem occurs else H
*/
HRESULT query(const std::string &queryStr,
std::vector<QueryObj> &queryVectorOut,
const AdditionalFilters *filters = nullptr);
private:
IWbemLocator *pLoc = nullptr;
IWbemServices *pSvc = nullptr;
};