Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2006

Tip: Looking for answers? Try searching our database.

Running processes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
plmanikandan@gmail.com - 23 Mar 2006 07:44 GMT
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

Regards,
Mani
Bruno van Dooren - 23 Mar 2006 08:39 GMT
> Hi,
>
[quoted text clipped - 7 lines]
> 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:

"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/en
umerating_all_processes.asp

For more details.

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

Signature

Kind regards,
   Bruno.
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"

Ben Voigt - 23 Mar 2006 16:01 GMT
>> Hi,
>>
[quoted text clipped - 13 lines]
> 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/op
enmutex.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
[quoted text clipped - 12 lines]
>
> If you were using .NET you would use the Process class for that.
Mihajlo Cvetanović - 23 Mar 2006 16:59 GMT
>>If exe1 already has a mutex, you can simply check in the other exe if it
>>is
[quoted text clipped - 3 lines]
> Except you should use OpenMutex instead, because you don't want to exclude
> exe1 from starting.

But if OpenMutex fails you should CreateMutex, right? But then there
might arise situation when both processes call OpenMutex, concludes that
there isn't one, then both call CreateMutex. To address this you must
finally check with the GetLastError after CreateMutex. That means that
OpenMutex is an extra call that achieves nothing.

CreateMutex doesn't automatically grants you ownership of the mutex.
Waiting functions do that (WaitForSingleObject et al.).
Ben Voigt - 23 Mar 2006 20:06 GMT
>>>If exe1 already has a mutex, you can simply check in the other exe if it
>>>is
[quoted text clipped - 12 lines]
> CreateMutex doesn't automatically grants you ownership of the mutex.
> Waiting functions do that (WaitForSingleObject et al.).

The OP has already done that in his singleton application.  Now he's asking
the question, is it possible to detect whether that application is running
from another application, and for that purpose he should use OpenMutex only.
Bruno van Dooren - 23 Mar 2006 21:17 GMT
> The OP has already done that in his singleton application.  Now he's
> asking the question, is it possible to detect whether that application is
> running from another application, and for that purpose he should use
> OpenMutex only.

Not true.
For the exe of which only 1 instance may be running (exe) it doesn't matter
if the mutext exists or not.
It just wants ownership. It tries to take it and bails out if it can't.

The managing app (exe1) only want to know if the mutex exists or not.
CreateMutex can achieve
the same thing as OpenMutex, as long as the InitialOwner parameter of
CreateMutex is set to 0, so
that it is not accidently owned.

Signature

Kind regards,
   Bruno van Dooren
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.