-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathSample.Service.h
100 lines (76 loc) · 2.56 KB
/
Sample.Service.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#pragma once
#include "Vutils.h"
#include <conio.h>
#include <vu>
#include <algorithm>
using namespace vu;
DEF_SAMPLE(ServiceManager)
{
if (!vu::is_administrator())
{
std::tcout << ts("You are not Administrator") << std::endl;
}
else
{
std::tstring driver_name = ts("WKE Driver");
std::tstring driver_display_name = ts("Windows Kernel Explorer Driver");
std::tstring driver_path = vu::get_current_directory();
#ifdef _WIN64
driver_path += ts("WKE64.sys");
#else // _WIN32
driver_path += ts("WKE32.sys");
#endif // _WIN64
// Create / Start / Stop / Delete
vu::VUResult ret = vu::VU_OK;
auto& sm = ServiceManager::instance();
std::tcout << ts("Press any key to create service ...") << std::endl; _getch();
ret = sm.install(driver_path, driver_name, driver_display_name);
if (ret != VU_OK)
{
std::tcout << sm.get_last_error_message() << std::endl;
}
std::tcout << ts("Press any key to start service ...") << std::endl; _getch();
ret = sm.start(driver_name);
if (ret != VU_OK)
{
std::tcout << sm.get_last_error_message() << std::endl;
}
std::tcout << ts("Press any key to stop service ...") << std::endl; _getch();
ret = sm.stop(driver_name);
if (ret != VU_OK)
{
std::tcout << sm.get_last_error_message() << std::endl;
}
std::tcout << ts("Press any key to delete service ...") << std::endl; _getch();
ret = sm.uninstall(driver_name);
if (ret != VU_OK)
{
std::tcout << sm.get_last_error_message() << std::endl;
}
// Dependents / Dependencies
std::tstring example = ts("WSearch");
std::tcout << example << std::endl;
std::tcout << ts("*Dependents:") << std::endl;
auto dependents = sm.get_dependents(example);
for (auto& dependent : dependents)
{
std::tcout << ts(" ") << dependent.lpServiceName << ts(" - ") << dependent.lpDisplayName << std::endl;
}
std::tcout << ts("*Dependencies:") << std::endl;
auto dependencies = sm.get_dependencies(example);
for (auto& dependency : dependencies)
{
std::tcout << ts(" ") << dependency.lpServiceName << ts(" - ") << dependency.lpDisplayName << std::endl;
}
// List Services
std::tcout << ts("*Services:") << std::endl;
auto pService = sm.query(example);
assert(pService != nullptr);
auto services = sm.get_services(VU_SERVICE_ALL_TYPES, SERVICE_RUNNING);
for (auto& e : services)
{
std::tcout << ts(" ") << e.lpServiceName << ts(" - ") << e.lpDisplayName << std::endl;
}
}
return vu::VU_OK;
}