My procedure works perfectly when there is another instance of my program running but otherwise it gets stuck in a constant loop. I've tryed all sorts and came here as a last resort.
There's not really much else I can say so here's my code:
{*Finds and ends previous instances of toMediaPlayer*}
procedure EndPrevious();
var PlayerProcess:TProcessEntry32;
Processes:THandle;
Complete, debug: Boolean;
Previous:Cardinal;
begin
//Takes a snapshot of the currently running processes
Processes := CreateToolHelp32SnapShot(TH32CS_SNAPALL, 0);
PlayerProcess.dwSize := SizeOf(TProcessEntry32);
//Searches for the toMediaPlayer Process
Process32First(Processes,PlayerProcess);
complete := False;
repeat
if PlayerProcess.szExeFile = 'toMediaPlayer.exe'
then begin
if not (PlayerProcess.th32ProcessID = GetCurrentProcessID)
then begin
//Closes the toMediaPlayer Process
TerminateProcess(OpenProcess(PROCESS_TERMINATE,False,
PlayerProcess.th32ProcessID),0);
Complete := True;
end;
end
else begin
Complete := False;
if Process32Next(Processes,PlayerProcess) = false then Complete := True; <HERE
end;
until Complete = True;
end;
{**}
Thanks for any help you can give
Squall