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

  • SEARCH
  • Home
  • 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

WinAPI OpenFile function returns HFILE, and GetFileTime for instance needs HANDLE. When I feed
I have a pure Winapi application that needs a few new features. One of
Here's the deal. My WinApp is running, right? in let's say process 'A'.It creates
How to well use the WinAPI to manage the fullscreen mode on windows's window
I've forgotten the WinAPI call to find out how much space is remaining on
I need to replace all WinAPI calls of the CreateFile, ReadFile, SetFilePointer, CloseHandle with
I`m writing a chat using WinSock2 and WinAPI functions. And I have a little
I'm learning about Win32 programming, and the WinMain prototype looks like: int WINAPI WinMain
How to detect IIS version using C#? Update: I meant from a winapp (actually
I'm trying to use the Win32 API to make a sub-thread that reads from

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.