Article View: comp.os.ms-windows.programmer.misc
Article #2921Re: How to avoid multiple instances of a program in NT and 95?
From: Pat Meenan
Date: Mon, 10 Feb 1997 00:00
Date: Mon, 10 Feb 1997 00:00
28 lines
1812 bytes
1812 bytes
>Sean Kennedy wrote:
>> A terrible hack could be upon startup immediately create a file in the
>> %TEMP% directory. If the create function returns a 'File exists'
>> return, otherwise, continue.
>
>This may be more terrible than you imagined. Do you intend that the
>program delete the file when it exits? What happens if the program
>crashes and the file is never deleted? In that case it would seem that
>the program could never be run again, unless the person running it was
>sophisticated enough to know to delete the file, and with most users
>that will never happen.
HANDLE hMutex;
if( (hMutex = CreateMutex( NULL, FALSE, "Unique mutex name here" )) !=
INVALID_HANDLE_VALUE )
{
if( GetLastError() == ERROR_ALREADY_EXISTS )
{
// do whatever you want to tell the user
}
}
The mutex handle will get closed when your app exits, but to be nice,
you may want to close it yourself.
-Pat
Technical Details
Message-ID:
<32ff5a20.8653663@news2.cais.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<5d4eeb$n6u$1@euler.space.net> <32f6d5ca.86355796@news.ecs.fullerton.edu> <32F88FB9.3129@bbn.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1124cf,3403ef0501dd273 X-Google-Attributes: gid1124cf,public X-Google-Thread: 105df1,3403ef0501dd273 X-Google-Attributes: gid105df1,public X-Google-Thread: f6ef4,3403ef0501dd273 X-Google-Attributes: gidf6ef4,public X-Google-Thread: 113dfb,3403ef0501dd273 X-Google-Attributes: gid113dfb,public From: pmeenan@ids2.idsonline.com (Pat Meenan) Subject: Re: How to avoid multiple instances of a program in NT and 95? Date: 1997/02/10 Message-ID: <32ff5a20.8653663@news2.cais.com> X-Deja-AN: 217833330 references: <5d4eeb$n6u$1@euler.space.net> <32f6d5ca.86355796@news.ecs.fullerton.edu> <32F88FB9.3129@bbn.com> organization: DigitalNow, Inc. reply-to: pmeenan@ids2.idsonline.com newsgroups: comp.os.ms-windows.programmer.misc,comp.os.ms-windows.programmer.win32,de.comp.os.ms-windows.programmer,fido.ger.windows.prog