1/* 2 * ReactOS ps - process list console viewer 3 * 4 * ps.c 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21#include <windows.h> 22#include <tlhelp32.h> 23 24static char* title = " PID PARENT TIME NAME\n"; 25char buf[256]; 26 27int main() 28{ 29 DWORD r; 30 HANDLE pl; 31 PROCESSENTRY32 pe; 32 HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE); 33 34 WriteFile(stdout, title, lstrlen(title), &r, NULL); 35 pl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 36 pe.dwSize = sizeof(PROCESSENTRY32); 37 pe.th32ParentProcessID = 0; 38 39 if (Process32First(pl, &pe)) do { 40 int hour; 41 int minute; 42 WORD fatdate; 43 WORD fattime; 44 HANDLE p = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pe.th32ProcessID); 45 FILETIME cr; 46 FILETIME ex; 47 FILETIME kt; 48 FILETIME ut; 49 GetProcessTimes(p, &cr, &ex, &kt, &ut); 50 FileTimeToDosDateTime(&cr, &fatdate, &fattime); 51 hour = (fattime & 0xf800) >> 11; 52 minute = (fattime & 0x07e0) >> 5; 53 wsprintf(buf,"%08X %08X %2d:%02d %s\n", pe.th32ProcessID, pe.th32ParentProcessID, hour, minute, pe.szExeFile); 54 WriteFile(stdout, buf, lstrlen(buf), &r, NULL); 55 CloseHandle(p); 56 pe.th32ParentProcessID = 0; 57 } while (Process32Next(pl, &pe)); 58 59 CloseHandle(pl); 60} 61/* 62BOOL 63STDCALL 64FileTimeToDosDateTime( 65 CONST FILETIME *lpFileTime, 66 LPWORD lpFatDate, 67 LPWORD lpFatTime 68 ); 69 */ 70