Allan_Fernandes
asked on
Kill Task like Task Mgr
I want my Uninstall.exe (running with admin rights) to Terminate my Application that was installed and is running with Std User Rights.
Whereas this works in OS above win XP it fails on Win XP.
Whereas this works in OS above win XP it fails on Win XP.
function Tform_Main.KillTask(ExeFileName: string): integer;
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOL;
FSnapshotHandle,ProcessHandl: THandle;
FProcessEntry32: TProcessEntry32;
begin
result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName)) or
(UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then
begin
ProcessHandl:=OpenProcess(PROCESS_TERMINATE,BOOL(0),FProcessEntry32.th32ProcessID) ;
Result := Integer(TerminateProcess(ProcessHandl, 0));
CloseHandle(ProcessHandl);
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
ASKER
The code you have given works only within the User
check if function FindExeProcess get valid Pid (>0) for different user. Is running exe 64 bit? or 32bit?
try change:
try change:
const
PROCESS_QUERY_LIMITED_INFORMATION = $1000;
...
hProcess := OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, False, PIDArray[i]);
...
ASKER
Sorry that does not help either.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
... and kill process by process id:
Open in new window