Solved

detect other program  is running

Posted on 2002-06-18
3
231 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

896 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

11 Experts available now in Live!

Get 1:1 Help Now