![]() |
Close Mutex of another process |
Post Reply
|
Page 123 6> |
| Author | |
hot.dok
Newbie
Joined: 12 June 2008 Status: Offline Points: 22 |
Post Options
Thanks(0)
Quote Reply
Topic: Close Mutex of another processPosted: 12 June 2008 at 6:40am |
|
Hi,
I need to close mutex created by another appication. Here is my code: bReturnVal = CreateProcess( NULL, "C:\\Program Files\\Skype\\Phone\\Skype.exe", NULL, NULL, FALSE, dwCreationFlags, NULL, NULL, &si, &process_info); if (bReturnVal = 0) { return 1; } Sleep(4000); HANDLE skypeOriginalMutex = OpenMutex( MUTEX_ALL_ACCESS, false, "SkypeMutex" ); if ( skypeOriginalMutex != NULL) { HANDLE res; DuplicateHandle(process_info.hProcess, skypeOriginalMutex, GetCurrentProcess(), &res, 0, false, DUPLICATE_CLOSE_SOURCE); CloseHandle(res); GetLastErrorLoc(); MessageBox(NULL, "Mutex released", "WOW", MB_OK); } The problem is that original handle is not closed. Please explain how can I close it? Regards |
|
![]() |
|
molotov
Moderator Group
Joined: 04 October 2006 Status: Offline Points: 17506 |
Post Options
Thanks(0)
Quote Reply
Posted: 12 June 2008 at 7:15am |
|
Hi hot.dok,
Just at a first glance... what does DuplicateHandle return? If failure, what does GetLastError() return?
Look at the doc for the hSourceHandle param:
Edited by molotov - 12 June 2008 at 7:17am |
|
|
Daily affirmation:
net helpmsg 4006 |
|
![]() |
|
ring0
Newbie
Joined: 09 June 2008 Location: India Status: Offline Points: 18 |
Post Options
Thanks(0)
Quote Reply
Posted: 12 June 2008 at 7:31am |
|
check if this helps: |
|
|
Cheers
- Ring0 |
|
![]() |
|
hot.dok
Newbie
Joined: 12 June 2008 Status: Offline Points: 22 |
Post Options
Thanks(0)
Quote Reply
Posted: 12 June 2008 at 7:40am |
|
molotov,
DuplicateHandle returns non zero value. And getlasterror return 0. The handle is connected to my process but not removed from skype.exe ring0, will check out thanks you guys |
|
![]() |
|
molotov
Moderator Group
Joined: 04 October 2006 Status: Offline Points: 17506 |
Post Options
Thanks(0)
Quote Reply
Posted: 12 June 2008 at 7:52am |
|
It looks like you duplicated and closed a handle in Skype.exe, that had the vaue returned by OpenMutex in your process. (In other words, it looks like you're duping / closing some random handle in skype.exe.)
|
|
|
Daily affirmation:
net helpmsg 4006 |
|
![]() |
|
hot.dok
Newbie
Joined: 12 June 2008 Status: Offline Points: 22 |
Post Options
Thanks(0)
Quote Reply
Posted: 12 June 2008 at 7:57am |
|
The handle is duplicated to my process but not closed on skype.exe. But with process explorer I can close the skype handle with no problem. Thus I such technique exists but possibly I'm on the wrong way.
|
|
![]() |
|
hot.dok
Newbie
Joined: 12 June 2008 Status: Offline Points: 22 |
Post Options
Thanks(0)
Quote Reply
Posted: 12 June 2008 at 7:59am |
|
One more thing. Due to MSDN:
DUPLICATE_CLOSE_SOURCE - Closes the source handle. This occurs regardless of any error status returned. So the skype mutex have to be closed but it is not. |
|
![]() |
|
molotov
Moderator Group
Joined: 04 October 2006 Status: Offline Points: 17506 |
Post Options
Thanks(0)
Quote Reply
Posted: 12 June 2008 at 8:02am |
Verify using PE that the handle you duplicate, is the handle you expect to be duplicating (the named mutex "SkypeMutex").
Say OpenMutex in your process returns 0x7c0. You pass hSkype, 0x7c0, GetCurrentProcess(), &hDup to DuplicateHandle. But, in hSkype, 0x7c0 was a handle to a registry key. You've just duped that registry key handle in your process and closed it in Skype. You need to get the source handle in skype.exe, not your process.
|
|
|
Daily affirmation:
net helpmsg 4006 |
|
![]() |
|
hot.dok
Newbie
Joined: 12 June 2008 Status: Offline Points: 22 |
Post Options
Thanks(0)
Quote Reply
Posted: 12 June 2008 at 8:16am |
|
The mutex that is attached to my process after duplicatehandle executed is "SkypeMutex". Also I see that reference count to SkypeMutex in skype.exe process is incremented. That's the only ways I can verify it's needed handle.
|
|
![]() |
|
hot.dok
Newbie
Joined: 12 June 2008 Status: Offline Points: 22 |
Post Options
Thanks(0)
Quote Reply
Posted: 12 June 2008 at 8:17am |
|
Also when I do OpenMutex it gets existing mutex created by skype. If skype is not run it returns error.
|
|
![]() |
|
Post Reply
|
Page 123 6> |
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |