Closing Applications from VB - Need an ans ASAP

I am creating a program in VB 6 that opens other applications like Word, Excel, IE, etc. I used ShellExecute to open the files/applications. Now I need a way to fully close the applications after I am done using them.

Things I thought baout were FindExecutable, TerminateProcess, but have not reallyhad much luck in determining if they will work  good or not. Need some help fast!!!!!!!!1
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What are you doing in the applications.  Can you do it under the application's VBA program control, or can you do it under program control from VB?
slimbxAuthor Commented:
Under program control from VB. I am using ShellExecte to open different files and application programs from with in my program.
Use the following code

Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE = &H10

Private Sub Command2_Click()
    lngreturn = FindWindow(vbEmpty, Window Caption)
    SendMessage lngreturn, WM_CLOSE, 0, 0
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

slimbxAuthor Commented:
In this statement,

lngreturn = FindWindow(vbEmpty, Window Caption)

I know that you dim a var as long (lngreturn)

.. vbEmpty would be a null handle?
, and Window Caption - would that be the title of the application window to close?

 Could you give me a example putting in some fake vars or something. I understand the code, but dont really have a way of telling what I cana nd need to put in there.
Suppose you have opened Experts Exchange in Netscape communicator gold, the caption of the title window shows "Visual Basic Question - Netscape". Use this as the parameter as the window caption. If you open Word, the caption would be "Microsoft Word - Document1". Use this. The exact caption of the window should be used.

I tested the given code with the Notepad.

I used

lngReturn = FindWindow(vbEmpty,"Untitled - Notepad".

It worked with me.
slimbxAuthor Commented:
Okay, with that in mind that you need to use the exact caption of the window, my program opens ANY file(s) in almost any application. So how can I know what file is opened and what the caption reads for this to work properly? I cant.

Isnt there any other API calls that can close applications.

App.PrevInstance will tell me how many instances of an app are open, is there any other property like that that can close the applications down though?

You have an array which will tell you what all windows are opened using your applications.

Use EnumWindows to get all the parent windows and loop through them to close the window which you want to close.

Redim the array
slimbxAuthor Commented:
Hate to ask, but do you happen to have any code examples of this. I have not reached this far into API calls for a while, and need a little help.
Give me your e-mail id. Mine is

I will send you a sample project.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.