ckeck for my process

Posted on 2005-04-24
Last Modified: 2010-04-05
how i can  check if there are running my process ???
if I know process exe name. I want cr eate some watch dog for watching is there  running my programm..
programs exe  name is "program.exe" ;D
Question by:andrezzz
    LVL 12

    Accepted Solution

    LVL 5

    Expert Comment

    Use this function:

    function TaskOpen(ExeFileName: string): boolean;
     const   //Displays whether a task is open or not
     PROCESS_TERMINATE=$0001;  //This probably not needed
     ContinueLoop: BOOLEAN;
     FSnapshotHandle: THandle;
     FProcessEntry32: TProcessEntry32;
                  //      result := 0;
                       FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
                       FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
                       ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32);

     while integer(ContinueLoop) <> 0 do
                 if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =UpperCase(ExeFileName))
                 or (UpperCase(FProcessEntry32.szExeFile) =
                 UpperCase(ExeFileName))) then
                 Result :=true ;
          ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);


    Example of use:

    if taskopen('program.exe') then
        messagedlg('The process is open' ,mtinformation,[mbok],0)
        messagedlg('The process is not open' ,mtinformation,[mbok],0)


    LVL 5

    Expert Comment

    My answer is very similar to the answer provided by esoftbg, so it up to you to see what you like

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now