mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 02:25:17 +00:00
Initial revision
svn path=/trunk/; revision=2397
This commit is contained in:
parent
16e5929c1c
commit
d3b8d085e2
2 changed files with 79 additions and 0 deletions
58
reactos/apps/tests/kill/kill.cpp
Normal file
58
reactos/apps/tests/kill/kill.cpp
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/* Kill for Win32 by chris@dbn.lia.net
|
||||||
|
* http://users.lia.net/chris/win32/
|
||||||
|
* Public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
inline int h2i(char x)
|
||||||
|
{
|
||||||
|
return (x + ((x & 0x40) >> 6) | ((x & 0x40) >> 3)) & 0x0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void msg(HANDLE out, LPCTSTR fmt...)
|
||||||
|
{
|
||||||
|
char tmp[256];
|
||||||
|
wvsprintf(tmp,fmt,(char*)&fmt+sizeof(fmt));
|
||||||
|
DWORD w;
|
||||||
|
WriteFile(out,tmp,lstrlen(tmp),&w,NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
HANDLE stderr = GetStdHandle(STD_ERROR_HANDLE);
|
||||||
|
|
||||||
|
LPTSTR cmdline = GetCommandLine();
|
||||||
|
|
||||||
|
//Scan command line to end of program name
|
||||||
|
while(*cmdline && *cmdline != ' ')
|
||||||
|
if(*cmdline++ == '"')
|
||||||
|
while(*cmdline && *cmdline++ != '"');
|
||||||
|
|
||||||
|
// Loop while we have parameters.
|
||||||
|
while(*cmdline)
|
||||||
|
{
|
||||||
|
//scan past spaces..
|
||||||
|
while(*cmdline == ' ')
|
||||||
|
cmdline++;
|
||||||
|
|
||||||
|
//read in pid
|
||||||
|
int pid = 0;
|
||||||
|
while(*cmdline)
|
||||||
|
pid = (pid << 4) + h2i(*cmdline++);
|
||||||
|
|
||||||
|
HANDLE p = OpenProcess(PROCESS_ALL_ACCESS,FALSE,pid);
|
||||||
|
if(p)
|
||||||
|
{
|
||||||
|
if(TerminateProcess(p,(unsigned int)-9))
|
||||||
|
msg(stdout,"Terminated PID: %08X\n",pid);
|
||||||
|
else
|
||||||
|
msg(stdout,"Couldn't kill PID: %08X, error=%d\n",pid,GetLastError());
|
||||||
|
CloseHandle(p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
msg(stderr,"No such PID: %08X, error=%d\n",pid,GetLastError());
|
||||||
|
}
|
||||||
|
}
|
21
reactos/apps/tests/kill/makefile
Normal file
21
reactos/apps/tests/kill/makefile
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#
|
||||||
|
|
||||||
|
PATH_TO_TOP = ../..
|
||||||
|
|
||||||
|
TARGET_NORC = yes
|
||||||
|
|
||||||
|
TARGET_TYPE = program
|
||||||
|
|
||||||
|
TARGET_APPTYPE = console
|
||||||
|
|
||||||
|
TARGET_NAME = kill
|
||||||
|
|
||||||
|
TARGET_SDKLIBS =
|
||||||
|
|
||||||
|
TARGET_OBJECTS = $(TARGET_NAME).o
|
||||||
|
|
||||||
|
include $(PATH_TO_TOP)/rules.mak
|
||||||
|
|
||||||
|
include $(TOOLS_PATH)/helper.mk
|
||||||
|
|
||||||
|
# EOF
|
Loading…
Reference in a new issue