Solved

Limiting an application to only one instance

Posted on 1998-12-14
6
145 Views
Last Modified: 2013-11-20
I need to know how to prevent more than one instance of my application from being loaded at the same time. If a user attempts to load the application while an instance is already running, the currently running instance should be brought up instead. Can anyone tell me how to do this?
0
Comment
Question by:jhanson040697
6 Comments
 

Expert Comment

by:kanni
ID: 1326188
Hi

You can find solutions with sample code in the codeguru.com site.
0
 

Accepted Solution

by:
kanni earned 100 total points
ID: 1326189
Hi

Get all the active application window handles,
Compare the Window names with your app name,
If any of the Window name is same as your app names then bring the window to top.
0
 
LVL 1

Expert Comment

by:fkurucz
ID: 1326190
there is a more simple solution using a named mutex (see CMutex or as kanni said an example at codeguru.com)

bye
  feri
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 1

Expert Comment

by:fkurucz
ID: 1326191
Ok, ok,
its not that complicated:

in your initialization module insert the following code:

// Check for existence of second Instance, and keep Mutex open
HANDLE hRunOnceMutex;
hRunOnceMutex = CreateMutex(NULL, FALSE, "EsKannNurEinenGeben");
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
    // some code to exit your program
}

you need not to call "CloseHandle(hRunOnceMutex)", because the mutex is freed automatically if your program exits.

bye,
  feri

0
 
LVL 2

Expert Comment

by:wyy_cq
ID: 1326192
fkurucz 's solution is common way in win32.
0
 

Author Comment

by:jhanson040697
ID: 1326193
The example on codeguru.com worked very well for me.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Tab names are off by one 5 49
How to know only "File created" with EventLog 3 29
maxBlock challenge 30 100
mapBully challenge 6 89
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now