Results 1 to 5 of 5

Thread: Closing Applications (API?)

  1. #1

    Thread Starter
    Hyperactive Member tomcatexodus's Avatar
    Join Date
    Feb 2001
    Posts
    372

    Unhappy



    Ok, Does anyone know how to close an application that is running (I suppose using API), by using the applications' pathname

    for example: closing windows' explorer using the string,
    c:\windows\explorer.exe

    Understand???

    (Is this possible??)

    Any help would be greatly appreciated!
    IWS

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Here's one way. Just use the name of the window's caption as an argument in the FindWindow. It has to be exact.

    Code:
    Option Explicit
    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
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Private Const WM_CLOSE = &H10
    
    Private Sub Command1_Click()
        Dim rc As Long
        rc = FindWindow(vbNullString, "Untitled - Notepad")
        SendMessage rc, WM_CLOSE, 0, 0
    End Sub

  3. #3
    Matthew Gates
    Guest
    Already answered this in your other thread.

  4. #4

    Thread Starter
    Hyperactive Member tomcatexodus's Avatar
    Join Date
    Feb 2001
    Posts
    372

    Wink

    Ok Matt,

    But when I put the code in, it didnt' work properly...

    If I have the path in Text1, and I want to close the application relating to that path by pressing Command2, what would I do to manipulate the code for that....

    (yes I'm an idiot )
    IWS

  5. #5
    Matthew Gates
    Guest
    Code:
    Private Sub Command2_Click()
        Call KillApp("" & Text1.Text & "")
    End Sub

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