Board index » cppbuilder » problem with TerminateProcess

problem with TerminateProcess


2004-01-11 04:02:27 AM
cppbuilder67
hi
i have made a small program that using borland c++ 5.5 that terminates a
process with the TerminateProcess function. now the program works fine, but
only if i terminate a process that has the same user. now what my problem is
that if i run my program as an administrator i am not able to terminate
processes from other users (as an admin i should be able to).
HANDLE FSnapshotHandle=CreateToolhelp32Snapshot(0x00000002, 0);
PROCESSENTRY32 plist32;
plist32.dwSize = sizeof(plist32);
ContinueLoop = Process32First(FSnapshotHandle, &plist32);
while (ContinueLoop) {
//----------- i am using this for windows 9x
char nov[255] ="";
for (int i = strlen(plist32.szExeFile)-strlen(p); i <=
strlen(plist32.szExeFile); i++) nov[i-strlen(plist32.szExeFile)+strlen(p)] =
plist32.szExeFile[i];
//------------------------------------------
if (!lstrcmpi(nov,p)) {
// i belive that at this point i am missing sommething to be able to get the
terminate process rights
TerminateProcess(OpenProcess((0x0001),0,plist32.th32ProcessID), 0);
}
ContinueLoop = Process32Next(FSnapshotHandle, &plist32);
}
CloseHandle(FSnapshotHandle);
 
 

Re:problem with TerminateProcess

hi
i have made a small program that using borland c++ 5.5 that terminates a
process with the TerminateProcess function. now the program works fine, but
only if i terminate a process that has the same user. now what my problem is
that if i run my program as an administrator i am not able to terminate
processes from other users (as an admin i should be able to).
HANDLE FSnapshotHandle=CreateToolhelp32Snapshot(0x00000002, 0);
PROCESSENTRY32 plist32;
plist32.dwSize = sizeof(plist32);
ContinueLoop = Process32First(FSnapshotHandle, &plist32);
while (ContinueLoop) {
//----------- i am using this for windows 9x
char nov[255] ="";
for (int i = strlen(plist32.szExeFile)-strlen(p); i <=
strlen(plist32.szExeFile); i++) nov[i-strlen(plist32.szExeFile)+strlen(p)] =
plist32.szExeFile[i];
//------------------------------------------
if (!lstrcmpi(nov,p)) {
// i belive that at this point i am missing sommething to be able to get the
terminate process rights
TerminateProcess(OpenProcess((0x0001),0,plist32.th32ProcessID), 0);
}
ContinueLoop = Process32Next(FSnapshotHandle, &plist32);
}
CloseHandle(FSnapshotHandle);
 

Re:problem with TerminateProcess

"saso badovinac" < XXXX@XXXXX.COM >wrote in message
Quote
now what my problem is that if i run my program as an
administrator i am not able to terminate processes from
other users (as an admin i should be able to).
Not necessarily. Depending on what process you are trying to terminate in
the first place, there is no guarantee that you can terminate the process.
There are some processes that are protected by the OS and simply are not
allowed to be terminated programmably.
Quote
HANDLE FSnapshotHandle=CreateToolhelp32Snapshot(0x00000002, 0);
Which OS are you programming for exactly? The Toolhelp API is not available
at all under NT4. Have a look at the following article for details about
obtaining process information regardless of OS:
HOWTO: Enumerate Applications Using Win32 APIs
support.microsoft.com/default.aspx
Quote
// i belive that at this point i am missing sommething to be able to get
the
terminate process rights

TerminateProcess(OpenProcess((0x0001),0,plist32.th32ProcessID), 0);
}
You are not testing the return value of both OpenProcess() and
TerminateProcess(). You should always check return values. Then you will
know when you need to call GetLastError() to find out why something fails.
Gambit
 

{smallsort}