CreateProcess only once.

In my application I'm using CreateProcess() function in order to invoke the "character map" execution.
By clicking a command from the toolbar, the user opens the characters map.
The problem is that I dont want to allow this operation if the "character map" is already running.

how can I do that ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:

CreateProcess() uses PROCESS_INFORMATION variable.
In that hProcess member will contain the handle to newly created process U can check for that

if(...hProcess != NULL)
     //Open character map

For that U may have to make PROCESS_INFORMATION's variable as the member function of that class. Pls see to it that by default and whenever U kill that process or if process not created successfully assign it to NULL.

Try it out.
Hi yoavo,

I agree with VinExpert, but I fear it's not enough for your purpose, because the ( hProcess != NULL ) will even be TRUE if the processe is terminated by a user. But you can use this given handle to find out if the process is still running, i.e.

class CMyApp : ...
 HANDLE m_hProcess;

CMyApp::CMyApp ()
 m_hProcess = NULL;

CMyApp::OnOpenCharMap()//message handler for the button
 if ( m_hProcess != NULL )
   DWORD exitCode;
   GetExitCodeProcess( m_hProcess, &exitCode );
   if ( exitCode == STILL_ACTIVE )
    return; // charmap is still running
 if ( CreateProcess( ..., &pi ) ) // create the process if not running
  m_hProcess = pi.hProcess;
  m_hProcess = NULL;

hope that helps,


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.