Click here to Skip to main content
15,074,668 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello Everyone..

Programatically am trying to run on Microsoft office 2007. The code looks like this:

char exe_arr[100]="E:\\setup.exe";
HINSTANCE hInst = ShellExecute(0,"open",exe_arr,"",0,SW_SHOW);

Anyhow after executing this, The code opens the office setup.exe...

And latter Am determining the status of the exe i.e., If exe is running the status is 1, And if exe is quit the status is 0.

To determine the exe status, the code looks like this:

int isRunning;

When i execute this code, FIND_PROC_BY_NAME returns 0 status, eventhough setup.exe is running..& it should return 1 status right ?

But this code works fine for other exe applications..

Can anyone tell, Why it is returning 0 status for office setup.exe ??

Thanks in advance..!!
Updated 26-Apr-12 4:04am
Code-o-mat 26-Apr-12 10:18am
How do you know it is running? If you check task manager, do you see a/the process called setup.exe?
Guru_C++ 27-Apr-12 0:02am
Yes.. I can see the setup.exe in task manager
Code-o-mat 27-Apr-12 3:49am
Then my next question would be -as Richard already asked- what is FIND_PROC_BY_NAME. Now, the name is quite obvious, what he probably means is -and it is also what i'd like to see- how does FIND_PROC_BY_NAME work? Do you have the source for this method? If possible, use "improve question" and add the code of this function. It is pretty unlikely that anyone will be able to tell you why it does not work without actually SEEING anything but its name.
Richard MacCutchan 26-Apr-12 10:54am
What is FIND_PROC_BY_NAME? It does not look like a Microsoft SDK function.
Guru_C++ 27-Apr-12 0:03am
FIND_PROC_BY_NAME: It determines whether the process is running or not.. If it is running then it returns 1 or else 0.
Richard MacCutchan 27-Apr-12 4:06am
As I said, this does not look like a Microsoft API so how exactly does it do that? Is it something that you wrote for yourself?

Mohibur Rashid 26-Apr-12 18:45pm
why not sending absolute path? i am just asking :)

You can use GetExitCodeProcess[^] and check for STILL_ACTIVE (259) to see if the process is still running or not.

A better method than polling for process completion, I think, would be to create the process with CreateProcess[^], then use WaitForSingleObject on the process handle to know exactly when the process exits.

Two reasons this is a better method:

1. "setup.exe" may or may not refer to the "setup.exe" you started. There may be more than one instance.

2. polling is a waste of processor resources, WFSO is a more efficient and elegant solution.

Guru_C++ 27-Apr-12 0:54am
Thank you.. It works fine... But if the setup.exe is run as administrator, then also CreateProcess wii=ll return 0 status.. Am not getting why it happens with Run as administrator..
Paul Heil 27-Apr-12 11:41am
If you want to create a process with increased permissions, then you need to use CreateProcessAsUser or CreateProcessesWithLogon.
you can enumerate all the active processes list and then you can check if your process is running or not.if the process is running,you can terminate that by using terminateprocess() window function;
you can have a look on the following sample[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900