-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_proc.c
73 lines (66 loc) · 1.79 KB
/
cmd_proc.c
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
#include <windows.h>
#include <tlhelp32.h>
#include "types.h"
#include "server.h"
#include "misc.h"
#include "globals.h"
int zXcmd_ps(pCommandData X)
{
#define command X->argv[0]
HANDLE hS;
PROCESSENTRY32 pe;
unsigned int r;
unsigned int n=0;
char *fileName;
pe.dwSize=sizeof(pe);
hS=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
wsprintf(X->sbuf,"+:%s| pid|thd|pr|filename",command);
sendStr(X);
for(r=Process32First(hS,&pe);r;r=Process32Next(hS,&pe))
{
if (chk4break(X))
return ~0;
/* wsprintf(sbuf,"%2x %2x %2d %2d %s\r\n",OpenProcess(PROCESS_TERMINATE,0,pe.th32ProcessID),
OpenProcess(PROCESS_TERMINATE,0,pe.th32ParentProcessID),
pe.cntThreads,pe.pcPriClassBase,pe.szExeFile);
*/
//GetLongPathName(pe.szExeFile,pe.szExeFile,MAX_PATH);
if (isWin98)
GetFullPathName(pe.szExeFile,MAX_PATH,pe.szExeFile,&fileName);
else
fileName=pe.szExeFile;
//wsprintf(sbuf,"+:ps| %8d %8x %8x %8d %2d %s",n,pe.th32ProcessID,pe.th32ParentProcessID,pe.cntThreads,pe.pcPriClassBase,fileName);
wsprintf(X->sbuf,"+:%s| %8X %3d %2d %s",command,pe.th32ProcessID,pe.cntThreads,pe.pcPriClassBase,fileName);
sendStr(X);
++n;
}
wsprintf(X->sbuf,"*:%s| %u processes currently running",command,n);
sendStr(X);
return 0;
}
int zXcmd_kl(pCommandData X)
{
#define command X->argv[0]
unsigned int pid;
HANDLE hP;
BOOL r=0;
if (X->argc)
{
pid=_atox(X->argv[X->argc]);
if (chk4break(X))
return ~0;
if (hP=OpenProcess(PROCESS_TERMINATE,0,pid))
{
r=TerminateProcess(hP,0);
CloseHandle(hP);
}
if (r)
wsprintf(X->sbuf,"*:%s| killed process \"0x%X\"",command,pid);
else
wsprintf(X->sbuf,"-:%s:0| could not kill process with pid \"0x%.8X\"",command,pid);
}
else
wsprintf(X->sbuf,"-:%s:5| pid of process to kill not specified",command);
sendStr(X);
return 0;
}