Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5960265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:48:10+00:00 2026-05-22T18:48:10+00:00

In my C++/winapi program I use an event object to detect if an instance

  • 0

In my C++/winapi program I use an event object to detect if an instance of my application is already running, in order to not let the second instance start.

But in the same time I want to allow multiple instances of the program to run if they are launched using a different user account. E.g. using “runas” command.
(That is: for each user account only 1 instance can run simultaneously)

I use the code that looks like this:

HANDLE hSingleInstance=OpenEvent(EVENT_MODIFY_STATE,FALSE,
                                   "Local\\SingleInstanceEventName");
if(hSingleInstance!=NULL) {
  // there is an instance already running
  SetEvent(hSingleInstance);// let know the 1st instance that we are trying to start
  CloseHandle(hSingleInstance);
  return 0; // exit the program
}
else {
  // this is the 1st instance
  hSingleInstance=CreateEvent(NULL,FALSE,FALSE, "Local\\SingleInstanceEventName");
}

It works as expected in XP – I can run only 1 instance using the same user account, and I can run multiple instances using multiple user accounts.

But in Windows 7, the OpenEvent() function always “finds” my event object, even if the event object is created using another user account. Because of this I cannot run multiple instances using different user accounts (as desired).

What should I change in my code to allow multiple instances be run using diffent user accounts in Windows 7?
Or maybe my approach is completely wrong, then what one is correct?

thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:48:10+00:00Added an answer on May 22, 2026 at 6:48 pm

    All you have to do is include the username in the name of the event somehow. I’m quite frankly a bit surprised that your scenario worked in XP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the Win32 API to make a sub-thread that reads from
I have an application consisting of two windows, one communicates to the other and
I write extensions to a C++ program. I write standard C/C++ dlls and I
Recently I tried to use /Wall Visual C++ option to enable all warnings and
I'm looking for a winapi function that will allow me to change current logged
I have a program that heavily uses std::map . Under Windows, much more memory
hello I have the following win32 program, and I have an EDITTEXT control that
If you've ever seen an application in the Adobe Creative Suite 5 (CS5), you
I would like to write some simple Mario-like game from scratch using language C.
having trouble getting my directx going I get the following error 1>Linking... 1>main.obj :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.