Results 1 to 17 of 17

Thread: Close an App

  1. #1

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702

    Close an App

    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


  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Use spy++ to get the name, use findwindow with the name, then use closewindow with the received hwnd to close it.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    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.
    Im not to good with API's.

    Got any examples?

  4. #4

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    Originally posted by duc
    Im not to good with API's.

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

  5. #5
    Lively Member da_haCKEr's Avatar
    Join Date
    Oct 2002
    Location
    Paradise Isle of Sri Lanka
    Posts
    116
    VB Code:
    1. 'In General section of Form
    2. private Declare Function CloseWindow Lib "user32" Alias "CloseWindow" (ByVal hwnd As Long) As Long
    3.  
    4. private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    5.  
    6. '
    7. Private Sub CloseApp()
    8. Dim RetVal as long
    9. RetVal=FindWindow(vbnullstring,"My Program")
    10. closewindow retval
    11. end sub
    .:JanuZ:.
    .:JanuZ:.XtremeSoft


  6. #6
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Atlanta, GA
    Posts
    280
    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
    OrdinaryGuy

  7. #7

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    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

  8. #8
    Fanatic Member seec77's Avatar
    Join Date
    Jan 2003
    Posts
    596
    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!
    Best Regards,
    seec77

    If you helped me, cosinder yourself thanked.

    Get each and every Garfield strip here!
    Here you can get all Calvin & Hobes strips!
    Damn UComics! It was probably unprofitable for them to allow us to just download Garfield and Calving & Hobes strips... so they made folder indexing unallowed on their server!!!

    I am 33% addicted to Counterstrike. What about you?
    I am 23% addicted to Star Wars. What about you?
    I am 0% addicted to Tupac. What about you?

  9. #9
    Lively Member da_haCKEr's Avatar
    Join Date
    Oct 2002
    Location
    Paradise Isle of Sri Lanka
    Posts
    116

    Cool Oh yeah

    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.
    .:JanuZ:.
    .:JanuZ:.XtremeSoft


  10. #10

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702

    Re: Oh yeah

    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.
    Nothings working. Im gonna search google for some.

  11. #11
    Fanatic Member seec77's Avatar
    Join Date
    Jan 2003
    Posts
    596
    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!
    Best Regards,
    seec77

    If you helped me, cosinder yourself thanked.

    Get each and every Garfield strip here!
    Here you can get all Calvin & Hobes strips!
    Damn UComics! It was probably unprofitable for them to allow us to just download Garfield and Calving & Hobes strips... so they made folder indexing unallowed on their server!!!

    I am 33% addicted to Counterstrike. What about you?
    I am 23% addicted to Star Wars. What about you?
    I am 0% addicted to Tupac. What about you?

  12. #12

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    i tried changing my program to AIM, AIM.exe , aim.exe , AOL Instant Messenger, Buddy List Window.

  13. #13
    Lively Member da_haCKEr's Avatar
    Join Date
    Oct 2002
    Location
    Paradise Isle of Sri Lanka
    Posts
    116

    Cool If you're using win9X

    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:
    1. Const TH32CS_SNAPHEAPLIST = &H1
    2. Const TH32CS_SNAPPROCESS = &H2
    3. Const TH32CS_SNAPTHREAD = &H4
    4. Const TH32CS_SNAPMODULE = &H8
    5. Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
    6. Const TH32CS_INHERIT = &H80000000
    7. Const MAX_PATH As Integer = 260
    8. Private Type PROCESSENTRY32
    9.     dwSize As Long
    10.     cntUsage As Long
    11.     th32ProcessID As Long
    12.     th32DefaultHeapID As Long
    13.     th32ModuleID As Long
    14.     cntThreads As Long
    15.     th32ParentProcessID As Long
    16.     pcPriClassBase As Long
    17.     dwFlags As Long
    18.     szExeFile As String * MAX_PATH
    19. End Type
    20. Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
    21. Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
    22. Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
    23. Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
    24. Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    25. Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
    26. Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
    27. Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
    28. Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
    29.  
    30. Private Sub Form_Load()
    31. Dim strProcName As String
    32. Dim ProcHandle As Long
    33. Dim NewProcHandle As Long
    34. Dim hSnapShot As Long, uProcess As PROCESSENTRY32
    35.    
    36.     hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
    37.     uProcess.dwSize = Len(uProcess)
    38.     r = Process32First(hSnapShot, uProcess)
    39.     Do While r
    40.         strProcName = Left$(uProcess.szExeFile, IIf(InStr(1, uProcess.szExeFile, Chr$(0)) > 0, InStr(1, uProcess.szExeFile, Chr$(0)) - 1, 0))
    41.         If UCase(strProcName) = "MSMSGS.EXE" Then
    42.            ProcHandle = uProcess.th32ProcessID
    43.            NewProcHandle = OpenProcess(STANDARD_RIGHTS_REQUIRED, 0, ProcHandle)
    44.            TerminateProcess NewProcHandle, GetExitCodeProcess(NewProcHandle, 0)
    45.         End If
    46.         r = Process32Next(hSnapShot, uProcess)
    47.     Loop
    48.     CloseHandle hSnapShot
    49. End Sub
    .:JanuZ:.
    .:JanuZ:.XtremeSoft


  14. #14

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    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]
    Last edited by duc; Oct 8th, 2003 at 05:57 PM.

  15. #15

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    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

  16. #16
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    BTW, CloseWindow API only minimizes a window. Try using PostMessage & WM_CLOSE.
    Please rate my post.

  17. #17
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    This works for me ( win 2000 and XP )... Have a test!
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width