Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <time.h>
- #include <stdio.h>
- #pragma warning(disable: 4996)
- int main(int argc, char* argv[])
- {
- HWND hWnd = 0;
- DWORD lastProcessId = 0;
- WCHAR processImageName[260];
- WCHAR msg[128];
- time_t Time;
- while (1)
- {
- HWND hCurrentWnd;
- do
- {
- Sleep(0x64u);
- hCurrentWnd = GetForegroundWindow();
- } while (hCurrentWnd == hWnd);
- hWnd = hCurrentWnd;
- if (hWnd)
- {
- DWORD dwProcessId;
- GetWindowThreadProcessId(hWnd, &dwProcessId);
- CloseHandle(hWnd);
- if (dwProcessId != lastProcessId)
- {
- HANDLE process;
- lastProcessId = dwProcessId;
- process = OpenProcess(0x1000u, 0, dwProcessId);
- if (process)
- {
- DWORD lpDwSize = 260;
- if (!QueryFullProcessImageNameW(process, 0, processImageName, &lpDwSize))
- {
- processImageName[0] = L'\0';
- }
- time(&Time);
- wsprintfW(msg, L"%s", _wasctime(localtime(&Time)));
- wprintf(L"%lu:%s | %s", dwProcessId, processImageName, msg);
- CloseHandle(process);
- }
- else
- {
- time(&Time);
- wsprintfW(msg, L"%s", _wasctime(localtime(&Time)));
- wprintf(L"%lu:Could not open process | %s", dwProcessId, msg);
- }
- }
- }
- else
- {
- time(&Time);
- wsprintfW(msg, L"%s", _wasctime(localtime(&Time)));
- wprintf(L"No foreground application | %s", msg);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement