hi, i need to close an outside program, i mean if there is a program running and its filename is lets say:
c:\program\someprogram.exe, so i want my program to simply close that program, any ideas ???
thankx in advance, yair
Printable View
hi, i need to close an outside program, i mean if there is a program running and its filename is lets say:
c:\program\someprogram.exe, so i want my program to simply close that program, any ideas ???
thankx in advance, yair
This will list all running file's by filename (C:\....) and give you the option to kill them.
App List and Kill
Kill, kill, kill!!!
Kill a.k.a Close :).
OKOKOK, i got it, i need to kil,
now the prob... HOW??
thnkx,
yair
Yeah, but "kill" is such a better word then "close". Maybe they could make coding less stressful by adding words like "Mangle", "Pummel", and "Annihilate". :)
You can also use SendMessage.
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
Const WM_CLOSE = &H10
Private Sub Command1_Click()
'Get Calculator's Handle and close it
MyhWnd = FindWindow(0&, "Calculator")
SendMessage MyhWnd, WM_CLOSE, 0&, 0&
End Sub
Follow the link Matt posted. Hell, you might learn something.
ok, thankx alot u guys...
bye,
yair
Also, if the Application you want to close does not have a caption, you can close it according to it's class.
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
Const WM_CLOSE = &H10
Private Sub Command1_Click()
'Get Calculator's Handle (By it's class) and close it
MyhWnd = FindWindow("SciCalc", 0&)
SendMessage MyhWnd, WM_CLOSE, 0&, 0&
End Sub
You could also do it the Sendkeys way. This will give the program focus and press alt+f4.
Code:AppActivate "The Caption of the Program"
SendKeys "%{F4}"
If you're trying to close a program that has something like, say, an unsaved file, you'll get a prompt asking to save, thereby not closing the program immediately using SendKeys. Try going to the VB Help, search for AppActivate, and see what "See Also" items it lists to see if there is already something similar. :)