Results 1 to 4 of 4

Thread: Find Programs

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 1999
    Posts
    46

    Post

    Hello, i need to use Windows API or any other tool to find out that a program have been executed on the computer.
    I need to find that a program with X caption has been executed and get her window-handle back.

    Thank you very much,
    Kiron.

  2. #2
    Junior Member
    Join Date
    Mar 2000
    Location
    India, Visakhapatnam
    Posts
    19

    Post

    Hi,
    I could not understand you clearly frame your question in a more detailed manner as for know i recomend using the CreateToolhelp32Snapshot along with Process32First And Process32Next API's to get a list of all the programs running and then get what you want with a host of window APi's like enumthreadwindows .
    i may not be right but if you be clear maybe i can help you.

    Reply to
    <[email protected]>
    Dinesh
    reply to
    <[email protected]>

  3. #3
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Post Use the FindWindow API

    It sounds like you know the window's caption, so it's easy to get the handle with the FindWindow API.

    For this example, start a project and drop a command button on the form. Then paste the following into the form's code window.
    Code:
    Option Explicit
    
    Private Declare Function FindWindow Lib "user32.dll" Alias _
        "FindWindowA" (ByVal lpClassName As Long, _
        ByVal lpWindowName As String) As Long
    
    Private Sub Command1_Click()
        'Say you want to get the handle to Notepad and display
        'it to the user. Call the function like this:
        
        Dim lHandle As Long, _
            sWindowCaption As String
            
        sWindowCaption = "Untitled - Notepad"
        
        lHandle = FindWindow(CLng(0), sWindowCaption)
        
        If lHandle = 0 Then  'The window isn't running
            MsgBox "The window: """ & sWindowCaption & """ is not currently open."
        Else
            MsgBox "The handle to """ & sWindowCaption & """ is: " & lHandle
        End If
    End Sub
    Run the project without Notepad running and click the command button. Now, leave the project running and open a new Notepad document (Start->Programs->Accessories->Notepad). Click the command button again and you get the handle.
    ~seaweed

  4. #4
    Junior Member
    Join Date
    Mar 2000
    Location
    India, Visakhapatnam
    Posts
    19
    Well Seeweed i think that would be perfect if we know the window caption well but we get a problem if we want to check for a part of the string i nwhich case findwindow won't work so the best thing according to me is to the EnumWindows API get handle and then find out to see if it a toplevel window or not by calling the GetParent Api depending upon the requirement and then use the GetWindowText Api to get the caption and search for a part of the string using the Instring function.

    Dinesh
    reply to
    <[email protected]>

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