Solved

detect other program  is running

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

13 Experts available now in Live!

Get 1:1 Help Now