how to make sure that application have just a single instance

hi,
I am writing a C application and i want to make sure that only one
instance of the application runs.
How do i do it??? I need the best way to achive this??

any help is appriciated.

Thanks
Ajitabh


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

You need to create a named mutex by calling CreateMutex() with lpName !=
NULL. Then call GetLastError() and check the value. If GetLastError()
returns ERROR_ALREADY_EXISTS then there is another instance of your
application running and you should exit this instance.

Brian

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ajitabh Prakash
Sent: Thursday, June 21, 2001 3:09 PM
To: NT Developers Interest List
Subject: [ntdev] how to make sure that application have just a single
instance

hi,
I am writing a C application and i want to make sure that only
one
instance of the application runs.
How do i do it??? I need the best way to achive this??

any help is appriciated.

Thanks
Ajitabh


You are currently subscribed to ntdev as: xxxxx@sginet.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

One (of many) options is to create a named event during initialization. When an instance of the application starts, and attempts to create this event, it will fail with “ERROR_ALREADY_EXISTS” if another instance of the app is running. This assumes that you’re writing a user-mode application.

Ed Lau

MidCore Software, Inc.
900 Straits Tpke
Middlebury, CT 06762

www.midcore.com

----- Original Message -----
From: Ajitabh Prakash
To: NT Developers Interest List
Sent: Thursday, June 21, 2001 5:09 PM
Subject: [ntdev] how to make sure that application have just a single instance

hi,
I am writing a C application and i want to make sure that only one
instance of the application runs.
How do i do it??? I need the best way to achive this??

any help is appriciated.

Thanks
Ajitabh


You are currently subscribed to ntdev as: xxxxx@midcore.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hi,

I read before you can usually use a named semaphore.
Try to create the semaphore with a unique name and it
will give an error if the semaphore already exists.

Joe McCloskey
Gamry Instruments, Inc.
xxxxx@gamry.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Ajitabh Prakash
Sent: Thursday, June 21, 2001 2:09 PM
To: NT Developers Interest List
Subject: [ntdev] how to make sure that application have just a single
instance

hi,
I am writing a C application and i want to make sure that only one
instance of the application runs.
How do i do it??? I need the best way to achive this??

any help is appriciated.

Thanks
Ajitabh


You are currently subscribed to ntdev as: xxxxx@gamry.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

I assume that your program is a Windows application.
If so, one simple way to do is that before your application is being
executed let it check if there already exists an instance with the
same name (of the application itself). Sure, you must give it a name.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Brian Palmer
Sent: Thursday, June 21, 2001 5:25 PM
To: NT Developers Interest List
Subject: [ntdev] RE: how to make sure that application have just a
single instance

You need to create a named mutex by calling CreateMutex() with lpName !=
NULL. Then call GetLastError() and check the value. If GetLastError()
returns ERROR_ALREADY_EXISTS then there is another instance of your
application running and you should exit this instance.

Brian

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ajitabh Prakash
Sent: Thursday, June 21, 2001 3:09 PM
To: NT Developers Interest List
Subject: [ntdev] how to make sure that application have just a single
instance

hi,
I am writing a C application and i want to make sure that only
one
instance of the application runs.
How do i do it??? I need the best way to achive this??

any help is appriciated.

Thanks
Ajitabh


You are currently subscribed to ntdev as: xxxxx@sginet.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@cyclone.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Ajitabh,
Brian is right. CreateMutex is optimal way of doing it.

I’m giving you the MS link for this using C++ app and
this would work even for console apps using C.

http://support.microsoft.com/support/kb/articles/Q243/9/5
3.ASP

thanks

Girish H.

You need to create a named mutex by calling CreateMutex() with lpName !=
NULL. Then call GetLastError() and check the value. If GetLastError()
returns ERROR_ALREADY_EXISTS then there is another instance of your
application running and you should exit this instance.

Brian

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ajitabh Prakash
Sent: Thursday, June 21, 2001 3:09 PM
To: NT Developers Interest List
Subject: [ntdev] how to make sure that application have just a single
instance

hi,
I am writing a C application and i want to make sure that only
one
instance of the application runs.
How do i do it??? I need the best way to achive this??

any help is appriciated.

Thanks
Ajitabh


You are currently subscribed to ntdev as: xxxxx@sginet.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@att.net
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com