40 lines
924 B
C++
40 lines
924 B
C++
#include <windows.h>
|
|
#include <psapi.h>
|
|
#include <tlhelp32.h>
|
|
#include <iostream>
|
|
#include <dwmapi.h>
|
|
#include <d3d9.h>
|
|
|
|
#pragma comment(lib, "d3d9.lib")
|
|
#pragma comment(lib, "dwmapi.lib")
|
|
|
|
DWORD GetProcessId(LPCSTR ProcessName) {
|
|
PROCESSENTRY32 pt;
|
|
HANDLE hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|
pt.dwSize = sizeof(PROCESSENTRY32);
|
|
if (Process32First(hsnap, &pt)) {
|
|
do {
|
|
if (!lstrcmpi(pt.szExeFile, ProcessName)) {
|
|
CloseHandle(hsnap);
|
|
return pt.th32ProcessID;
|
|
}
|
|
} while (Process32Next(hsnap, &pt));
|
|
}
|
|
CloseHandle(hsnap);
|
|
return 0;
|
|
}
|
|
|
|
std::string RandomString(const int len) {
|
|
static const char alphanum[] =
|
|
"0123456789"
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
"abcdefghijklmnopqrstuvwxyz";
|
|
std::string tmp_s;
|
|
tmp_s.reserve(len);
|
|
|
|
for (int i = 0; i < len; ++i) {
|
|
tmp_s += alphanum[rand() % (sizeof(alphanum) - 1)];
|
|
}
|
|
|
|
return tmp_s;
|
|
} |