home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HomeWare 14
/
HOMEWARE14.bin
/
os2
/
cenv2_19.arj
/
KILL.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1994-03-08
|
4KB
|
95 lines
EXTPROC CEnvi
/***********************************************************************
*** Kill.cmd - CEnvi program to kill a running process by reference ***
*** ver.1 to its ID, partial name, or full name, or by full or ***
*** partial name of it Window. ***
***********************************************************************/
#include <PMdll.lib>
#include <WinTools.lib>
#define NO_ERROR 0 // return code from most successful DosCalls
KillQuietMode = False;
DosKillProcess(ActionCode,ProcessID)
// kill specified ProcessID using action code DKP_PRECESSTREE or DKP_PROCESS
{
#define DKP_PROCESSTREE 0 // kill process and all descendents, if created by this process
#define DKP_PROCESS 1 // kill any process even if not created by this process
#define ORD_DOS32KILLPROCESS 235
return DynamicLink("doscalls",ORD_DOS32KILLPROCESS,BIT32,CDECL,ActionCode,ProcessID)
}
MaybeKill(KillSpec,id,fullname) // if KillSpec matches any part of ProcSpec, then kill
{ // the id of ProcSpec; return TRUE if killed (or tried)
// divide this process id into numbers and parts so we can compare
// against any one of these types
root = SplitFileName(fullname).name;
sprintf(name,"%s%s",root,SplitFileName(fullname).ext);
if ( (0 != id && id == atoi(KillSpec))
|| 0 == strnicmp(KillSpec,fullname,lSpecLen = strlen(KillSpec))
|| 0 == strnicmp(KillSpec,root,lSpecLen)
|| 0 == strnicmp(KillSpec,name,lSpecLen) ) {
// this id matched, and so try to kill it
rc = DosKillProcess(DKP_PROCESS,id);
if ( !KillQuietMode ) {
if ( NO_ERROR == rc ) {
printf("%s has been killed.\n",fullname);
} else {
printf("\aError %d in DosKillProcess() from id %d\n",rc,id);
}
}
return(TRUE);
}
return(False);
}
main(argc,argv)
{
if ( argc != 2 || !strcmp(argv[1],"/?") || !strcmpi(argv[1],"help") ) {
Instructions();
} else {
// build list of all running processes
ProcList = ProcessList();
assert( NULL != ProcList );
ProcCount = 1 + GetArraySpan(ProcList);
// check each running process against this ID, whether it be name, or id
// number, or full or partial name, and try to kill it if it matches
for ( i = 0; i < ProcCount; i++ )
MaybeKill(argv[1],ProcList[i].id,ProcList[i].name);
// build list of all window switch titles
SwitchList = WinQuerySwitchList(Info().hab);
assert( SwitchList != NULL );
SwitchCount = 1 + GetArraySpan(SwitchList);
for ( i = 0; i < SwitchCount; i++ ) {
if ( 0 == WinQuerySwitchEntry(SwitchList[i],SwEntry) ) {
if ( !MaybeKill(argv[1],SwEntry.process,SwEntry.title) ) {
if ( (FullTitle = GetWindowTitle(SwEntry.hwnd)) ) {
MaybeKill(argv[1],SwEntry.process,FullTitle);
}
}
}
}
}
}
Instructions()
{
printf("\n")
printf("Kill - Kill a running process by name, Window name, process ID.\n")
printf("\n")
printf("SYNTAX: Kill ProcessName | WindowTitle | ProcessID\n")
printf("\n")
printf("Where: ProcessName - Full or partial name of running process\n")
printf(" WindowTitle - Full Window title\n")
printf(" ProcessID - Numeric ID of the process to kill\n")
printf("\n")
printf("Example: Kill e.exe\n")
printf("\n")
}