OK, my eyes are hurting from searching the forums for an answer. Whats the code to close an outside app. Say I wanted to close AIM or something. Thanks. Now im going to go wash my eyeballs.
-quac
http://www.sniffum.com/link.gif
Printable View
OK, my eyes are hurting from searching the forums for an answer. Whats the code to close an outside app. Say I wanted to close AIM or something. Thanks. Now im going to go wash my eyeballs.
-quac
http://www.sniffum.com/link.gif
Use spy++ to get the name, use findwindow with the name, then use closewindow with the received hwnd to close it.
Im not to good with API's.Quote:
Originally posted by Sastraxi
Use spy++ to get the name, use findwindow with the name, then use closewindow with the received hwnd to close it.
Got any examples?
If anyone could show me that would be nice. Also I already tried the code that Hack posted. I am trying to close AIM because it interferes with my cousins program so he wants me to have it close aim when it starts. THXQuote:
Originally posted by duc
Im not to good with API's.
Got any examples?
VB Code:
'In General section of Form private Declare Function CloseWindow Lib "user32" Alias "CloseWindow" (ByVal hwnd As Long) As Long private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long ' Private Sub CloseApp() Dim RetVal as long RetVal=FindWindow(vbnullstring,"My Program") closewindow retval end sub
Wierd, I did a search on VBF and found hundreds of examples on how to do so. Maybe you forgot to press the "perform search" button
http://vbforums.com/search.php?s=&ac...der=descending
I tried all of the examples there and none of them worked. The code posted above does not work either....hmm....i tried planet source code too. AIM is invincible :-P
did you try changing the "My Program" to work on aim?? anyway, just so you know, if the value of retval is 0, then it means it didn't find the window! check if it actually finds the hwnd of aim. another way to do it, is to use the sendmessage api and send a wm_close message to aim!
You have to replace "My Window" with the actual title of the program window. I don't use AIM, but I think that its title should be "AOL Instant Messenger". Check the title bar.
Nothings working. Im gonna search google for some.Quote:
Originally posted by da_haCKEr
You have to replace "My Window" with the actual title of the program window. I don't use AIM, but I think that its title should be "AOL Instant Messenger". Check the title bar.
what did you change "My Program" to that it didn't work? and did you check if the program actually finds the window?? cause then, that means that the closing part didn't work!
i tried changing my program to AIM, AIM.exe , aim.exe , AOL Instant Messenger, Buddy List Window.
This code should do the trick if you are using Win9x, but for Windows version running the NT kernel, there's some more things to be done to gain access to the process. I didn't do that because I couldn't find the values of the constants needed to gain access. :( The MSDN is very bad in that way. They should list the value of the Constant along with its description.
Anyway, If u r using Win9X, this should work. Replace "MSMSGS.EXE" with the exe name of AIM.
BTW, This code is not very good since I have modified the code written by somebody else. (ALLAPI)
VB Code:
Const TH32CS_SNAPHEAPLIST = &H1 Const TH32CS_SNAPPROCESS = &H2 Const TH32CS_SNAPTHREAD = &H4 Const TH32CS_SNAPMODULE = &H8 Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE) Const TH32CS_INHERIT = &H80000000 Const MAX_PATH As Integer = 260 Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * MAX_PATH End Type Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long) Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long) Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long Private Const STANDARD_RIGHTS_REQUIRED = &HF0000 Private Sub Form_Load() Dim strProcName As String Dim ProcHandle As Long Dim NewProcHandle As Long Dim hSnapShot As Long, uProcess As PROCESSENTRY32 hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&) uProcess.dwSize = Len(uProcess) r = Process32First(hSnapShot, uProcess) Do While r strProcName = Left$(uProcess.szExeFile, IIf(InStr(1, uProcess.szExeFile, Chr$(0)) > 0, InStr(1, uProcess.szExeFile, Chr$(0)) - 1, 0)) If UCase(strProcName) = "MSMSGS.EXE" Then ProcHandle = uProcess.th32ProcessID NewProcHandle = OpenProcess(STANDARD_RIGHTS_REQUIRED, 0, ProcHandle) TerminateProcess NewProcHandle, GetExitCodeProcess(NewProcHandle, 0) End If r = Process32Next(hSnapShot, uProcess) Loop CloseHandle hSnapShot End Sub
OK, wait....Since AIM just minimizes when you do the code where u fill in "My Program" I need a code where it finds the program and kills the app. I think i found teh handle using spy++ [forgot bout this post]
er one more thing. I already have code posted in the declarations section so what should i do with any new declarations code the people post? :( I'm in desperate need of a VB book. Obviously :blush:
BTW, CloseWindow API only minimizes a window. Try using PostMessage & WM_CLOSE.
This works for me ( win 2000 and XP )... Have a test!