Re: Running processes




"Bruno van Dooren" <bruno_nos_pam_van_dooren@xxxxxxxxxxx> wrote in message
news:836C91F9-9711-47D1-B994-9AE1F56E4463@xxxxxxxxxxxxxxxx
Hi,

I have written a win32 console application(exname1.exe) which runs for
ten minutes.I am calling this exname1.exe from another exe named
exname.exe using shellexecuteex.Now from exname.exe coding i have to
check whether exname1.exe is already running or not.How to find whether
a win32 console application is already runing or not from another win32
console application.I need only one copy of exe has to run(for that i
have already used createmutex in exename1.exe.But now i want to know
from exname.exe whether exename1.exe is running or not).How to find all
the processes or particular exe running in the computer using vc++6.0

If exe1 already has a mutex, you can simply check in the other exe if it
is
running or not. call CreateMutex in your other exe and check the error
code.
From MSDN:

Except you should use OpenMutex instead, because you don't want to exclude
exe1 from starting.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/openmutex.asp

Return Values
If the function succeeds, the return value is a handle to the mutex object.

If the function fails, the return value is NULL. To get extended error
information, call GetLastError.

If a named mutex does not exist, the function fails and GetLastError returns
ERROR_FILE_NOT_FOUND.



"If the mutex is a named mutex and the object existed before this function
call, the return value is a handle to the existing object, GetLastError
returns ERROR_ALREADY_EXISTS, bInitialOwner is ignored, and the calling
thread is not granted owernship. "

This will tell you if the mutex already exists or not. Hence you know if
the
exe1 is running or not. Remebmber to close the mutex handle afterwards.

A general way of checking if a process is running (using win32) would be
to
use the Process Status API (PSAPI). Check this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/enumerating_all_processes.asp
For more details.

If you were using .NET you would use the Process class for that.

--

Kind regards,
Bruno.
bruno_nos_pam_van_dooren@xxxxxxxxxxx
Remove only "_nos_pam"




.



Relevant Pages

  • Re: Synchronised Read/Write Problem
    ... A mutex will help you if you had a true Singleton object. ... Sam Santiago ... >> access to this external EXE behave in a single threaded manner. ...
    (microsoft.public.dotnet.distributed_apps)
  • Re: Checking for another instance of an application
    ... start the same exe twice from the exact same location. ... Start the app using the mapped path ... your app and using that to name the mutex is a good idea. ... > Gary Novosel ...
    (microsoft.public.vb.general.discussion)
  • Re: How to allow a specific number of Instances of my app?
    ... copy of the EXE, rename it or put it into a different folder and run the EXE ... make a mutex that is not dependant on the file name. ... another terminal server session, or a second session in XP fast user ...
    (microsoft.public.vb.general.discussion)
  • Re: checking whether particular exe or process is running?
    ... You can prevent multiple execution of processes using named mutexes. ... providing each process a unique mutex name, then a process of the two can ... a win32 console application is already runing or not from another win32 ... console application.I need only one copy of exe has to run(for that i ...
    (microsoft.public.vc.language)
  • Running processes
    ... ten minutes.I am calling this exname1.exe from another exe named ... exname.exe using shellexecuteex.Now from exname.exe coding i have to ... a win32 console application is already runing or not from another win32 ... console application.I need only one copy of exe has to run(for that i ...
    (microsoft.public.dotnet.languages.vc)