Solved

detect other program  is running

Posted on 2002-06-18
3
237 Views
Last Modified: 2013-11-20
Hi,Experts:  
  my program has some functions only can process when one other independent program is running.
  I have a question about this, it is possible to detect if other program is already running in the system.
  please help me, simple sample code will be very appreciated. I am using VC++ 6 and win2k.
  thank you very much!


--pigangel
 
0
Comment
Question by:pigangel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
ghimireniraj earned 80 total points
ID: 7091689
Hi pigangel,

Check out the topic "PROCESS WALKING" in MSDN.

Roughly this might be a way.

Using

Process32First(...)
Process32Next(...)

Iterate through the all the currently running processes.  Each time you will be retrieving process info into a structure  into PROCESSENTRY32 .

Check PROCESSENTRY32  to see if your desired process is running. look into that structure and find out how you can identify your the one you are looking for...One simple info  may be the szExeFile Path and filename of the executable file for the process.


--Niraj






0
 

Expert Comment

by:arunsrk
ID: 7091810
First of all
Create your own class name for your window
if you are using MFC use the Follwing Code in
InitInstance() Function of your application if you are following classic sdk style then WNDLCASS is already there..

// Register your unique class name that you wish to use
   
    WNDCLASS wndcls;
    memset(&wndcls, 0, sizeof(WNDCLASS));
    wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
    wndcls.lpfnWndProc = ::DefWindowProc;
    wndcls.hInstance = AfxGetInstanceHandle();
    wndcls.hIcon = LoadIcon(IDR_MAINFRAME);
    wndcls.hCursor = LoadCursor( IDC_ARROW );
    wndcls.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
    wndcls.lpszMenuName = NULL;

//Specify your own class name for using FindWindow later
   
    wndcls.lpszClassName = _T("PIGANGEL'S_CLASS");
    if(!AfxRegisterClass(&wndcls))
    {
         AfxMessageBox(_T("Class Registration Failed"));
         return FALSE;
    }

In the Second Application where you want to detect whether the window is running use the following code ..
here you get the handle of the application if your window is running.. You get the handle if the window is hidden too..
    HWND hWnd = ::FindWindow(_T("PIGANGEL'S_CLASS"),NULL);
    if(hWnd != NULL)
    {
     // Window Present You can do anything you want here
    }
    else
    {
       // Application not running
    }
0
 

Author Comment

by:pigangel
ID: 7091888
Hi,Niraj, your solution works perfect!

Arunsrk, the independent program is not handled by me, so your suggestion is not appliable to my qunestion, but I believe it will work on other scenario.

thank you very much!

-- pigangel
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 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