how does procexp close a mutex held by another process?

后端 未结 2 370
广开言路
广开言路 2021-01-03 08:03

I am trying to close a mutex that is being held by a process on Windows using Win32 functions. This can be done using procexp but I need to do it programmatically without us

相关标签:
2条回答
  • 2021-01-03 08:41

    Use NtQuerySystemInformation() to retrieve an array of open handles, loop through the array until you find the desired mutex handle in the target process, then close it using DuplicateHandle() by specifying the DUPLICATE_CLOSE_SOURCE flag.

    The following article explains it in more detail:

    HOWTO: Enumerate handles

    0 讨论(0)
  • 2021-01-03 08:59

    Just adding a complete answer. I had to add the following the following code to handles.cpp after the mutex is recognized:

         HANDLE realHandle;  
         ret = DuplicateHandle(processHandle, (HANDLE)handle.Handle, GetCurrentProcess(), &realHandle, 0, TRUE, DUPLICATE_CLOSE_SOURCE);  
    
             if(!ret)  
                   printf("DuplicateHandle Problem!");  
    
             if (!CloseHandle(realHandle))  
        {  
          printf("Problem closing the copied handle");  
        }  
        printf("", realHandle);  
      }  
    
    0 讨论(0)
提交回复
热议问题