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 6988207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:02:44+00:00 2026-05-27T19:02:44+00:00

I want to close a handle to a mutex located in another process, so

  • 0

I want to close a handle to a mutex located in another process, so I can run more than one instance of the application.

I already know this can be done, see Process Explorer. Example: Windows Minesweeper (Windows 7) uses a mutex to only allow one game, so I thought I would use it as an example since it’s pre-installed with Windows and therefore easier for you guys to guide me.

The mutex that I need to close is \Sessions\1\BaseNamedObjects\Oberon_Minesweeper_Singleton, which I found using Process Explorer.

After closing this mutex I was able to launch two games of Minesweeper, but I want to do this in my program using C++.

After some searching I have found that I might need the API DuplicateHandle. So far I haven’t been able to close the handle on this mutex.

Here is my code so far:

#include <Windows.h>
#include <iostream>

using namespace std;

void printerror(LPSTR location){
    printf("Error: %s_%d", location, GetLastError());
    cin.get();
}

int main(){
    DWORD pid = 0;
    HWND hMineWnd = FindWindow("Minesweeper", "Minesveiper");
    GetWindowThreadProcessId(hMineWnd, &pid);
    HANDLE hProc =OpenProcess(PROCESS_DUP_HANDLE, 0, pid);
    if(hProc == NULL){
        printerror("1");
        return 1;
    }
    HANDLE hMutex = OpenMutex(MUTEX_ALL_ACCESS, TRUE, "Oberon_Minesweeper_Singleton");
    if(hMutex == NULL){
        printerror("2");
        return 2;
    }
    if(DuplicateHandle(hProc, hMutex, NULL, 0, 0, FALSE, DUPLICATE_CLOSE_SOURCE) == 0){
        printerror("3");
        return 3;
    }
    if(CloseHandle(hMutex) == 0){
        printerror("4");
        return 4;
    }
    return 0;
}

This code returns 0, but the mutex is still there, and I am not able to launch more games of Minesweeper. I think some of my parameters to DuplicateHandle are wrong.

  • 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-27T19:02:45+00:00Added an answer on May 27, 2026 at 7:02 pm

    The second argument to DuplicateHandle expects “an open object handle that is valid in the context of the source process”, however I believe the handle you’re passing in would only be valid within the current process (OpenMutex creates a new handle to an existing mutex object). You’ll likely need to determine what the mutex’s handle is in the remote process, and use that value when calling DuplicateHandle.

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

Sidebar

Related Questions

I want to close a socket so I can reopen one on the same
I want to do following things from main thread/process: Communicate to another process using
In my WiX installer I want to gracefully close the application that is about
I want to send wm_close to another process, with which i want end that
How can I handle an event where I click on the red close button
I want to close a System.Windows.Forms.Form if the user clicks anywhere outside it. I've
I want to close a tab in my tab control when the mouse wheel
I want to close the dialog box when you click outside of the dialog,
I don't want a close window menu item in the task bar context menu
The background: My form has a TWebBrowser. I want to close the form with

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.