Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Single Instance of Console App?

Posted on 2000-04-13
5
Medium Priority
?
373 Views
Last Modified: 2013-11-20
Can anyone suggest me a fool proof way to limit a console app to single instance?

If somebody tries to start the console app in any or all the possible ways it should pop up th eprevious instance.

0
Comment
Question by:nv3prasad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:MT_MU
ID: 2713809
Some good info can be found at...

http://www3.pgh.net/~newcomer/nomultiples.htm
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2717929

You can just create a named, global object and check for it before continuing.

"popping up" another instance isn't allowable: what if the user is typing in some other window? Abruptly popping up another window without the user expecting it is rude. (And, Windows 2000 and newer are _finally_ actively preventing apps from performing this miserable behaviour!)

-- begin file only1.cpp --

// compile with
//   cl /W4 only1.cpp

#include <stdio.h>
#include <windows.h>

void main()
{
   HANDLE hPrev = CreateEvent(NULL, FALSE, FALSE, "SomeUniqueNameHere");
   if (GetLastError() == ERROR_ALREADY_EXISTS)
   {
      printf("Already running!\n");
      return;
   }

   printf("Not already running.\n");
   printf("Press a key to exit\n");
   getchar();
}

-- end of only1.cpp --

..B ekiM
0
 
LVL 1

Author Comment

by:nv3prasad
ID: 2728107
I tried what you said but does not seem to work, can you post me a sample which can have only one instance of a console application.

My E-mail is pnarahar@hotmail.com
0
 
LVL 1

Author Comment

by:nv3prasad
ID: 2728680
Hi Mike,

I figured out that you were not wrong and it was my mistake to reject your answer.

I will award you the points.

Can you help me to close the console window without it asking me "Press any key to continue" ( this is not your code though!)

Thank you

nv3prasad
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 150 total points
ID: 2729035
> Can you help me to close the console window without
 > it asking me "Press any key to continue" ( this is not
 > your code though!)

If it's not my code, then where is it coming from? Which OS are you using?

..B ekiM
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

664 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