CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2002
    Location
    Bangalore, India
    Posts
    1

    Smile To find if a process is running.

    Hi Techies,

    Can anyone tell me an API or a logic to find if a process is running on a system (local and remote). The problem is detailed below:

    1. I launch an application say "Notepad.exe" from another application say "MyApp".
    2. Notepad.exe continues to run after I close "MyApp".
    3. The second time I run "MyApp", it should check if there is already an instance of "Notepad.exe" running. If yes, it should not launch it.

    From the code I will be passing only the application name "Notepad.exe". I am not creating a thread. Is there a single API call which takes the application name and tells if the application is already running in the system [OR] is there a simple method to find this out.

    Regards,
    KalpanaManuPrasad

  2. #2
    Join Date
    Feb 2001
    Location
    Germany
    Posts
    20
    Hi,

    I think the api function "FindWindow" should help you.

    Winni

  3. #3
    Join Date
    Nov 2002
    Posts
    39
    Use API functions Process32First, Process32Next to iterate through all opened processes.

  4. #4
    Join Date
    Sep 2002
    Location
    Belarus - Tirol, Austria
    Posts
    647
    1. Process32First, Process32Next does not work on Win NT for ex.
    It's special for Win 9x ( in ToolHelp lib ) and else Win 2000... supports it. So for Win NT there are functions from psapi.dll ( EnumProcesses,...), PDH-functions and hidden hive of registry (HKEY_PERFORMANCEDATA). There is no one way to enumerate processes for all Win-platforms.

    2. If FindWindow,
    There is one question: Are U simple need already running notepad.exe or it must be notepad.exe with some information from previsious process ( opened document in it for ex. ).
    Because U can have situation when U have many notepad.exe running on machine, so if you want to find notepad.exe running by your process U must know for ex. a caption of this notepad window. And use it for finding current notepad instance.
    "UNIX is simple; it just takes a genius to understand its simplicity!"

  5. #5
    Join Date
    Nov 2002
    Posts
    39
    OSVERSIONINFO os;
    os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&os);
    if (os.dwPlatformId == VER_PLATFORM_WIN32_NT)
    {

    }
    else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
    {
    }
    else
    {
    }

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

Featured