Click here to Skip to main content
15,881,852 members
Articles / Desktop Programming / MFC
Article

Single Instance Checker

Rate me:
Please Sign up or sign in to vote.
3.45/5 (10 votes)
17 Apr 2002 95.8K   1.2K   25   20
Only 1 instance of your application can run in the same time

Introduction

If you want your application have just only instance is run in the same time, you only download and use it.

Step 1: Add file "LimitSingleInstance.h" to your project. This file is written by Microsoft. :-)

Step 2: Run UUIDGEN.EXE to get ID. This tool is written by Micorosft :-)

Step 3: Declare a variable

CLimitSingleInstance g_SingleInstanceObj(TEXT("{ID get from UUIDGEN}"));

for ex: CLimitSingleInstance g_SingleInstanceObj(TEXT("{addb6c1d-d98d-40f4-8041-0eb6b8bc884c}"));

Step 4: InitInstance()

Only add this line to check instance and make sure only 1 instance can run.

if (g_SingleInstanceObj.IsAnotherInstanceRunning()) return FALSE;

VERY and VERY SIMPLE.

I get this information and "LimitSingleInstance.h" from KnowledgeBase of Mirosoft site.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Vietnam Vietnam
// -------------------------------- //
// Personal Information //
// -------------------------------- //
Yahoo ID : dothanhtrongnghia
AOL : trongnghia95
ICQ : 151917542
Cell Phone : (84)-(90)-(3329867)

Comments and Discussions

 
QuestionThanks, bigZidane. Pin
TigerRex1-Nov-14 22:13
TigerRex1-Nov-14 22:13 
GeneralMy vote of 1 Pin
Mercede15-Oct-09 23:20
Mercede15-Oct-09 23:20 
GeneralWhatta bunch Pin
GoddFadda3-Jan-03 18:04
GoddFadda3-Jan-03 18:04 
GeneralWhatever Pin
Anonymous5-Sep-02 23:51
Anonymous5-Sep-02 23:51 
Generalwinxp, multiple user Pin
19-Apr-02 9:21
suss19-Apr-02 9:21 
GeneralRe: winxp, multiple user Pin
Michael Dunn19-Apr-02 11:59
sitebuilderMichael Dunn19-Apr-02 11:59 
GeneralRe: winxp, multiple user Pin
bigZidane19-Apr-02 17:21
bigZidane19-Apr-02 17:21 
GeneralWhat's the point with UUIDGEN.EXE Pin
Ernest Laurentin18-Apr-02 4:44
Ernest Laurentin18-Apr-02 4:44 
GeneralRe: What's the point with UUIDGEN.EXE Pin
18-Apr-02 23:35
suss18-Apr-02 23:35 
GeneralRe: What's the point with UUIDGEN.EXE Pin
thenickname10-Apr-05 11:13
thenickname10-Apr-05 11:13 
GeneralBug Pin
Tim Smith18-Apr-02 4:23
Tim Smith18-Apr-02 4:23 
GeneralRe: Bug Pin
18-Apr-02 5:55
suss18-Apr-02 5:55 
GeneralHm... Pin
George17-Apr-02 22:28
George17-Apr-02 22:28 
GeneralRe: Hm... Pin
bigZidane17-Apr-02 22:43
bigZidane17-Apr-02 22:43 
GeneralRe: Hm... Pin
George17-Apr-02 22:52
George17-Apr-02 22:52 
GeneralRe: Hm... Pin
bigZidane17-Apr-02 22:58
bigZidane17-Apr-02 22:58 
GeneralRe: Hm... Pin
Jim A. Johnson18-Apr-02 4:17
Jim A. Johnson18-Apr-02 4:17 
GeneralRe: Hm... Pin
18-Apr-02 5:58
suss18-Apr-02 5:58 
GeneralRe: Hm... Pin
venkpai20-Oct-05 12:47
venkpai20-Oct-05 12:47 
GeneralRe: Hm... Pin
Mercede15-Oct-09 23:21
Mercede15-Oct-09 23:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.