Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello to all.
A small question. How do I close an application by name in Visual Basic 6.0? (Not closing by window caption, but by application running on the backgroud.) I have found how I can have a list of programs running on the background, and I can add them to a ListBox. I would like to know how I can click on one of them (in the listbox), and the appropriate application to close (terminate).I'm using windows 98.
A have tried and tried and nothing yet.
Thank you all for your help.
:-)

Here is the source code for a program that will show you how to close other windows (it doesn't look pretty here, so just copy it and paste it in a new project):
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_CLOSE = &H10Private Sub Form_Load()
Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
'Ask for a Window title
Ret = InputBox("Enter the exact window title:" & vbNewLine & "Note: must be an exact match")
If Ret = "" Then Exit Sub
'Search the window
WinWnd = FindWindow(vbNullString, Ret)
If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
'Post a message to the window to close itself
PostMessage WinWnd, WM_CLOSE, 0&, 0&End Sub

Thank you Phyre for your time. It works fine.
Sometimes though I need to close an application on the End Task Panel, and that application may not have an active window. I know the full path and the excecutable file. How can I close an application using those?
E.G. "C:\Program Files\Anapplication\app.exe"
Any help?
Thank you again in advance for your time.
:-)

well...i havent tried the code above, but assuming it works, and you say you have a list of programs that are running...then you can run the executable, and watch the list to see if it changes, and when it does, find the new name, then close it with the above code, and then close anything with the same name. i dunno if that would work, but its worth a try.
eaw8806
sorry i cant give you code...dont have acces to VB.

The code works just fine. the only problem is that you must have a window caption to work with. What I am trying to do is to close a program running on the background. EG If I press CTRL+ALT+DEL I can see my keyboard program running on the background (I have one of those programmable ones). So that program doesn't have a window so I cant use the window caption. But I can find out the path and the executable filename. Is there a way to enter for example CloseApp "C:\Program Files\KeyboardApp.exe" where CloseApp is a function writen in VB, so i can End Task that EXE?
Any help would be much appreasiated. Thank you..

hmmm...it would be hard, because any program can change their own caption quite easily...the caption might be the same as whats in ctrl alt del...i think theres a way to view it in VB...but im not sure. hope that helps..
eaw8806

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |