Akhilesh Pandey
Akhilesh Pandey

Reputation: 896

C++ program to bring a process to foreground if already running otherwise create a new process

I am trying to learn windows programming. I would like to launch an executable program.exe (say) from c++ code. I am able to achieve this by using CreateProcess() method in windows. However, my problem is if the process is already created and running in the background then the windows for program.exe should come to foreground otherwise a new process should be created and brought to the foreground. Any help will be appreciated.

Upvotes: 1

Views: 2317

Answers (2)

Vlad Feinstein
Vlad Feinstein

Reputation: 11311

Is that program.exe written by you? This functionality is better handled there: on start you check if there is already an instance running and if there is - activate it. Otherwise - what do you do if there are multiple instances of program.exe already running?

Upvotes: 0

Remy Lebeau
Remy Lebeau

Reputation: 596001

Look at Win32 API functions such as the following:

Upvotes: 2

Related Questions