-
Notifications
You must be signed in to change notification settings - Fork 2
/
Priority.cpp
67 lines (50 loc) · 1.58 KB
/
Priority.cpp
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
#include <windows.h>
#include "Priority.h"
#include "ProcessList.h"
#include <stdio.h>
CPriorityService::CPriorityService()
: CNTService(TEXT("Priority"), TEXT("Digital Design Priority for Windows 10"))
, m_hStop(0)
{
m_dwControlsAccepted = 0;
m_dwControlsAccepted |= SERVICE_ACCEPT_STOP;
}
void CPriorityService::Run(DWORD dwArgc, LPTSTR * ppszArgv) {
// report to the SCM that we're about to start
ReportStatus(SERVICE_START_PENDING);
m_hStop = ::CreateEvent(NULL, TRUE, FALSE, NULL);
// TODO: You might do some initialization here.
// Parameter processing for instance ...
// If this initialization takes a long time,
// don't forget to call "ReportStatus()"
// frequently or adjust the number of milliseconds
// in the "ReportStatus()" above.
// report SERVICE_RUNNING immediately before you enter the main-loop
// DON'T FORGET THIS!
ReportStatus(SERVICE_RUNNING);
#ifdef _DEBUG
int iCount = 0;
#endif
// main-loop
// If the Stop() method sets the event, then we will break out of
// this loop.
while (::WaitForSingleObject(m_hStop, 10) != WAIT_OBJECT_0)
{
CProcessList pl;
pl.Initialize();
pl.EnumProcesses();
Sleep(2000);
}
ReportStatus(SERVICE_STOP_PENDING);
if (m_hStop)
::CloseHandle(m_hStop);
ReportStatus(SERVICE_ACCEPT_STOP);
}
void CPriorityService::Stop() {
// report to the SCM that we're about to stop
// TODO: Adjust the number of milliseconds you think
// the stop-operation may take.
ReportStatus(SERVICE_STOP_PENDING, 5000);
if (m_hStop)
::SetEvent(m_hStop);
}