Results 1 to 12 of 12

Thread: Closeing Program

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    82
    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

  2. #2
    Guest
    This will list all running file's by filename (C:\....) and give you the option to kill them.

    App List and Kill

  3. #3
    Lively Member
    Join Date
    Mar 2000
    Location
    Fort Lauderdale, FL USA
    Posts
    112
    Kill, kill, kill!!!
    Damonous

  4. #4
    Guest
    Kill a.k.a Close .

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    82
    OKOKOK, i got it, i need to kil,
    now the prob... HOW??
    thnkx,
    yair

  6. #6
    Lively Member
    Join Date
    Mar 2000
    Location
    Fort Lauderdale, FL USA
    Posts
    112
    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".
    Damonous

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

  8. #8
    Lively Member
    Join Date
    Mar 2000
    Location
    Fort Lauderdale, FL USA
    Posts
    112
    Follow the link Matt posted. Hell, you might learn something.
    Damonous

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    82
    ok, thankx alot u guys...
    bye,
    yair

  10. #10
    Guest
    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

  11. #11
    Guest
    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}"

  12. #12

    Yeah, but...

    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.

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