Computing.Net > Forums > Programming > Closing an application in VB6

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Closing an application in VB6

Reply to Message Icon

Name: VASS
Date: July 14, 2003 at 19:58:56 Pacific
OS: Win 98
CPU/Ram: 256 mb
Comment:

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.
:-)



Sponsored Link
Ads by Google

Response Number 1
Name: phyre
Date: July 15, 2003 at 21:02:56 Pacific
Reply:

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 = &H10

Private 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


0

Response Number 2
Name: VASS
Date: July 16, 2003 at 16:06:27 Pacific
Reply:

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.
:-)


0

Response Number 3
Name: eaw8806
Date: July 16, 2003 at 18:38:56 Pacific
Reply:

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.


0

Response Number 4
Name: VASS
Date: July 16, 2003 at 22:56:19 Pacific
Reply:

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..


0

Response Number 5
Name: eaw8806
Date: July 18, 2003 at 19:20:03 Pacific
Reply:

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


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Closing an application in VB6

Process In VB www.computing.net/answers/programming/process-in-vb/13016.html

wininet.ocx and VB6 www.computing.net/answers/programming/wininetocx-and-vb6/12953.html

Compiled code readable parts www.computing.net/answers/programming/compiled-code-readable-parts/12176.html