How do I identify a copy of my process already in memory?

I want to create a program that will have only one instance in memory. Like
in ‘Windows Commander 32’ - there’s an option to allow 1 copy of it at a
time.
What kind of check should I use in order to ensure this behavior?
I know that the process name ‘wincmd.exe’ doesn’t represent a unique ID for
the ‘Windows Commander 32’ program, since I created a copy of the
executable ‘wincmd.exe’ (to ‘test.exe’) and ‘Windows Commander 32’ still
knew that it was ‘Windows Commander 32’ trying to create a copy and so
opened the already opened copy that I had.
Like for the ‘Explorer.exe’ program, you can have multiple copies running
at the same time -> this is NOT what I want.

Many thanks, Alon.

In WinMain create named mutex.
If CreateMutex returns OK, then it’s first instance.
If it fails, then GetLastError.
If it returns ERROR_INVALID_HANDLE this is not first instance of
our app.

Hope this helps.

Regards, Dennis

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of
xxxxx@AppStream.co.il
Sent: Sunday, April 16, 2000 12:00 AM
To: File Systems Developers
Subject: [ntfsd] How do I identify a copy of my process already in
memory?

I want to create a program that will have only one instance in
memory. Like
in ‘Windows Commander 32’ - there’s an option to allow 1 copy of it at a
time.
What kind of check should I use in order to ensure this behavior?
I know that the process name ‘wincmd.exe’ doesn’t represent a
unique ID for
the ‘Windows Commander 32’ program, since I created a copy of the
executable ‘wincmd.exe’ (to ‘test.exe’) and ‘Windows Commander 32’ still
knew that it was ‘Windows Commander 32’ trying to create a copy and so
opened the already opened copy that I had.
Like for the ‘Explorer.exe’ program, you can have multiple copies running
at the same time -> this is NOT what I want.

Many thanks, Alon.


You are currently subscribed to ntfsd as: xxxxx@yahoo.com
To unsubscribe send a blank email to $subst(‘Email.Unsub’)


Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com

Hello,

In both cases CreateMutex will succeed returning the
valid handle. One needs to call GetLastError() and it
will return ERROR_ALREADY_EXIST for the second
instance.

Make sure that you keep the handle open throughout the
execution of your program.

-Prasad

— Dennis wrote:
> In WinMain create named mutex.
> If CreateMutex returns OK, then it’s first instance.
> If it fails, then GetLastError.
> If it returns ERROR_INVALID_HANDLE this is not first
> instance of
> our app.
>
> Hope this helps.
>
> Regards, Dennis
>
>
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com]On Behalf
> Of
> > xxxxx@AppStream.co.il
> > Sent: Sunday, April 16, 2000 12:00 AM
> > To: File Systems Developers
> > Subject: [ntfsd] How do I identify a copy of my
> process already in
> > memory?
> >
> >
> > I want to create a program that will have only one
> instance in
> > memory. Like
> > in ‘Windows Commander 32’ - there’s an option to
> allow 1 copy of it at a
> > time.
> > What kind of check should I use in order to ensure
> this behavior?
> > I know that the process name ‘wincmd.exe’ doesn’t
> represent a
> > unique ID for
> > the ‘Windows Commander 32’ program, since I
> created a copy of the
> > executable ‘wincmd.exe’ (to ‘test.exe’) and
> ‘Windows Commander 32’ still
> > knew that it was ‘Windows Commander 32’ trying to
> create a copy and so
> > opened the already opened copy that I had.
> > Like for the ‘Explorer.exe’ program, you can have
> multiple copies running
> > at the same time -> this is NOT what I want.
> >
> > Many thanks, Alon.
> >
> > —
> > You are currently subscribed to ntfsd as:
> xxxxx@yahoo.com
> > To unsubscribe send a blank email to
> $subst(‘Email.Unsub’)
> >
>
>
>
>
>
> Do You Yahoo!?
>
> Talk to your friends online with Yahoo! Messenger.
>
> http://im.yahoo.com
>
>
> —
> You are currently subscribed to ntfsd as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
> $subst(‘Email.Unsub’)
>
>

=====
Prasad S. Dabak
Director of Engineering, Windows NT/2000 Division
Cybermedia Software Private Limited
http://www.cybermedia.co.in
Co-author of the book “Undocumented Windows NT”
ISBN 0764545698


Do You Yahoo!?
Send online invitations with Yahoo! Invites.
http://invites.yahoo.com