-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseractivitycheck.cpp
More file actions
75 lines (60 loc) · 1.9 KB
/
useractivitycheck.cpp
File metadata and controls
75 lines (60 loc) · 1.9 KB
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
#include "useractivitycheck.h"
#include <iostream>
#include <Windows.h>
#include <tlhelp32.h>
#pragma comment(lib, "user32")
constexpr int INFO_BUFFER_SIZE = 15000;
bool userChecks() {
TCHAR tUsername[INFO_BUFFER_SIZE] = { '\0' };
DWORD dBuffCharCount = INFO_BUFFER_SIZE;
if (GetUserName(tUsername, &dBuffCharCount)) {
const wstring home_dir = L"C:\\Users\\" + (wstring)tUsername;
const wstring desktop_dir = home_dir + L"\\Desktop\\*";
const wstring documents_dir = home_dir + L"\\Documents\\*";
const wstring downloads_dir = home_dir + L"\\Downloads\\*";
std::cout << "\nFile count [Desktop]: " << getFileCount(desktop_dir);
std::cout << "\nFile count [Documents]: " << getFileCount(documents_dir);
std:: cout << "\nFile count [Downloads]: " << getFileCount(downloads_dir);
}
else {
std::cerr << "\nCouldn't get username";
}
std::cout << "\nProcess count: " << getRunningProcessCount();
return false;
}
int getFileCount(wstring tDirName) {
WIN32_FIND_DATA w32FindData;
HANDLE hFind = FindFirstFile(tDirName.c_str(), &w32FindData);
int fileCount = 0;
if (hFind == INVALID_HANDLE_VALUE) {
std::cerr << "\nFailed to get handle to find files.";
return -1;
}
do {
fileCount++;
} while (FindNextFile(hFind, &w32FindData) != 0);
return fileCount < 4 ? 0 : fileCount - 3;
}
int getRunningProcessCount() {
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE) {
std::cerr << "\nFailed to get handle to process snapshot.";
return -1;
}
PROCESSENTRY32 pe32{};
pe32.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hProcessSnap, &pe32)) {
CloseHandle(hProcessSnap);
std::cerr << "\nFailed to get first process in process snapshot.";
return -1;
}
int procCount = 0;
do {
procCount++;
} while (Process32Next(hProcessSnap, &pe32));
CloseHandle(hProcessSnap);
return procCount;
}
bool hasUnusedBrowser() {
return false;
}