[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Closing a program with another program :)

Posted on 2004-10-28
5
Medium Priority
?
171 Views
Last Modified: 2010-04-05
Hey there,

I have a program that i've made, I want to make another program which will close that first program.
So program A - main program
program B - second program

Program A is opened - whenever, at system startup user startup....
They can then open program B at any stage and terminate program A.

Make sense?

0
Comment
Question by:wildzero
[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
  • 4
5 Comments
 
LVL 5

Accepted Solution

by:
Hypoviax earned 400 total points
ID: 12439416
This code can kill a program by exename (programA.exe):

function KillTask(ExeFileName: string): integer;
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: 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
Result := Integer(TerminateProcess(OpenProcess(
PROCESS_TERMINATE, BOOL(0),
FProcessEntry32.th32ProcessID), 0));
ContinueLoop := Process32Next(FSnapshotHandle,
FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;

If you don't know the name of the program or need more detail have a look at my solution to a similar question:

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21164286.html

Regards,

Hypoviax
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12439425
i.e you would use it like this in program b:

killtask(programA.exe);

Hypoviax
0
 
LVL 17

Assisted Solution

by:TheRealLoki
TheRealLoki earned 100 total points
ID: 12439586
var
              ahandle := FindWindow('Notepad', 'readme.txt - Notepad');
              if aHandle <> 0 then
                sendmessage(aHandle,wm_Close,0,0);

this will find the window (classname, windowname)
and send it a close message....
nice simple way of closing

e.g.

0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12439665
or you could do this:

postmessage(findwindow(nil,'WINDOWCAPTION'),wm_close,0,0);

which is even simpler

But the killtask procedure is perhaps more useful if you want to terminate by exename

Regards,

Hypoviax
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12477425
Thanks,

Hypoviax
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

656 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