Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

TerminateProcess(), Task Manager...

Posted on 2002-06-14
7
Medium Priority
?
232 Views
Last Modified: 2010-04-04
I wrote a client/server software. I login client from server and logged pc runs Counter Strike game. When i logout i am terminating all running visible windows. It works fine but if i try to run Counter Strike again it generates error so it doesn't run. It also happens with Fifa sometimes. But this problem started after the new version of CS game. If i terminate Counter Strike using Ctrl + Alt + Del so it works fine again. This is happening in win98 i didn't try other os. I also tried to kill DDhelp (DirectX) as written MSDN but no chance. I like to know what does ctrl + alt + del uses and how does it force terminate applications?

Termination code i wrote is:

function TEasyUtils.KillTask(pid: Int64): boolean;
var
  hw: THandle;
  ename: string;
begin
  Result := False;
  if (pid > 0) and (pid <> GetCurrentProcessId) then
  begin
    hw := OpenProcess(PROCESS_ALL_ACCESS, False, pid);
    if hw > 0 then
    try
      Result := TerminateProcess(hw, 0);
    finally
      CloseHandle(hw);
    end;
  end;
end;

I call this like:

var
  pid: Cardinal;
begin
  GetWindowThreadProcessId(winhwn, @pid);
  KillTask(pid);
end;

Thanks...
0
Comment
Question by:Dumani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 34

Expert Comment

by:Slick812
ID: 7080031
you might try to ask the app to Close with
PostMessage(hAppHandle,WM_CLOSE,0,0); so it can maybe shut down and save finalization info to file, before you jerk the process and wack the app out before it can close it's self down. If it still don't close, then kill the process.
0
 
LVL 1

Author Comment

by:Dumani
ID: 7080143
Thanks but i have tried that, that doesn't really work. I want to simulate Task Manager Terminate Process...
0
 
LVL 17

Expert Comment

by:geobul
ID: 7083239
Hi,
Change either
function KillTask(pid: DWORD): boolean;
or
hw := OpenProcess(PROCESS_TERMINATE, False, DWORD(pid));
and try again.

Regards, Geo
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:Dumani
ID: 7083293
Thanks GEO but that's not the solution
0
 
LVL 20

Accepted Solution

by:
Madshi earned 400 total points
ID: 7083408
I'm not sure what the task manager does exactly. But he's kindly asking the process to end. Only if the process doesn't do after 5 seconds, he forces it with TerminateProcess.

Some ideas:

(1) Post WM_CLOSE to the *main window*. That's important. It's wrong to post it to the application handle, that can not even work. And it's also wrong to post it to any window, just post it to the MAIN window.
(2) Try sending WM_QUERYENDSESSION to the main window. If the process accepts that (see the documentation), send a WM_ENDSESSION afterwards and then call TerminateProcess.
(3) Try posting a WM_QUIT to the main thread (PostThreadMessage). That's definately NOT what the task manager does, but it might be worth a try, nevertheless. It works fine for some processes, but not for all.

Regards, Madshi.
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9010895
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept answer from Madshi

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question