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