Jump to content

How to kill a mutex?


Recommended Posts

I've seen that AutoHotKeyNet has the following function:

<KillMutex>

However, Google is failing to show me any results for autoit having something similar, and I vastly prefer Autoit.

I know how to kill the mutex in process explorer, but I want a standalone application to be able to do it.

the path for the mutex is: \BaseNamedObjects\DAoCi1

I wish I knew what exactly that path meant (if anyone knows a term I should Google to learn about that please let me know). This is the AHK script to kill the mutex:

<Hotkey F1>
   <SendPC Local>
   <KillMutex \BaseNamedObjects\DAoCi1>
   <KillMutex \BaseNamedObjects\DAoCi2>

So, my question is: How can I kill this mutex in autoit? And also, where can I find a list of UDF's not included in the standard Autoit install?

Thanks!

Link to comment
Share on other sites

So, my question is: How can I kill this mutex in autoit? And also, where can I find a list of UDF's not included in the standard Autoit install?

Thanks!

you could ask in the hotkeynet forum how KillMutex is implemented and the use DllCall() to do the same, if possible.

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

you could ask in the hotkeynet forum how KillMutex is implemented and the use DllCall() to do the same, if possible.

Kurt

I tried to look at the source code (AutoHotKey is open source) but I couldn't find the killmutex function. I probably just don't know where to look.

But, the idea is, I get the source code in something like C or C++, and make it into a DLL so my autoit script can call it? So I should be asking for the source code for that function, right?

Link to comment
Share on other sites

I tried to look at the source code (AutoHotKey is open source) but I couldn't find the killmutex function. I probably just don't know where to look.

But, the idea is, I get the source code in something like C or C++, and make it into a DLL so my autoit script can call it? So I should be asking for the source code for that function, right?

AutoHotkey is NOT HotkeyNet! You really have to ask in the HotkeyNet forum: http://www.hotkeynet.com/

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

If you know the handle of mutex this shoud kill the mutex:

DllCall("kernel32.dll", "int", "ReleaseMutex", "hwnd", $hMutex)
DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hMutex)
Ok, so my hwnd is "\BaseNamedObjects\DAoCi1"... but what would I put for the $hMutex? I only know how to multi thread with pthread libraries. I tried a value of 1 and it didn't work.

AutoHotkey is NOT HotkeyNet! You really have to ask in the HotkeyNet forum: http://www.hotkeynet.com/

Kurt

Good point. My mistake.
Link to comment
Share on other sites

Ok, so my hwnd is "\BaseNamedObjects\DAoCi1"... but what would I put for the $hMutex? I only know how to multi thread with pthread libraries. I tried a value of 1 and it didn't work.

Good point. My mistake.

I`m not familiar with HotkeyNet, I don't know what is \BaseNamedObjects\DAoCi1.

hwnd is type of variable $hMutex(handler for your mutex). I don't know how to get handler from this \BaseNamedObjects\DAoCi1.

When the words fail... music speaks.

Link to comment
Share on other sites

Ok, so my hwnd is "\BaseNamedObjects\DAoCi1"... but what would I put for the $hMutex? I only know how to multi thread with pthread libraries. I tried a value of 1 and it didn't work.

Good point. My mistake.

take a look at _Singleton() in Misc.au3 (AutoIT include dir)... It uses CreateMutex() and contains everything you might need.

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

  • 1 year later...

iow:

goal: the possibility to run 2+ instances of the game.

By default, you can run only 2 instances, when trying to run the 3th, you get an error, there is a mutex somewhere:\

What I got for every instance: PID, winTitle, whandle;

how can I seek&destroy this mutex, or bypass it?

Link to comment
Share on other sites

whit this code found on another thread I think I can kill a mutex... just need to find the name!

#RequireAdmin
#include <WinAPI.au3>
HotKeySet("{ESC}", "_Escape"); ESC to exit
Global Const $MUTEX_ALL_ACCESS = 0x1F0001
Global $hMutexGlobal
$name = "???????????????????????????????????????????????????????????????"

While 1
    ConsoleWrite("Mutex Exists: " & (_MutexExists($name) = 1) & @CRLF)
    $hMutexGlobal = _MutexOpen($name)
    ConsoleWrite("Mutex Handle: " & $hMutexGlobal & @CRLF)

    If _ReleaseMutex($hMutexGlobal) = 1 Then
        MsgBox(0, '', "Mutex Released!" & @CRLF & "Mutex Exists: " & (_MutexExists($name) = 1))
    Else
        ConsoleWrite("Mutex Released: False" & @CRLF)
        ConsoleWrite("Mutex Exists: " & (_MutexExists($name) = 1) & @CRLF)
    EndIf
    Sleep(1000)
WEnd

Func _MutexOpen($szMutexName)

    Local $tSECURITY_ATTRIBUTES = DllStructCreate("dword Length;ptr SecurityDescriptor;int InheritHandle")
    DllStructSetData($tSECURITY_ATTRIBUTES, "Length", DllStructGetSize($tSECURITY_ATTRIBUTES))
    DllStructSetData($tSECURITY_ATTRIBUTES, "InheritHandle", 1); inherit the handle;<- THIS!!!
    Local $hMutex = DllCall("kernel32.dll", "hwnd", "CreateMutex","ptr", DllStructGetPtr($tSECURITY_ATTRIBUTES),"int", 1,"str", $szMutexName)
    If @error Or Not $hMutex[0] Then Return 0
    Return $hMutex[0]
EndFunc  ;==>_MutexOpen

Func _MutexOpen_($szMutexName)
    Local $hMutex = DllCall("kernel32.dll", "hwnd", "OpenMutex", "int", $MUTEX_ALL_ACCESS, "int", 0, "str", $szMutexName)
    If IsArray($hMutex) And $hMutex[0] Then Return $hMutex[0]
    Return 0
EndFunc  ;==>_MutexOpen_




Func _MutexExists($szMutexName)
    Local $hMutex = DllCall("Kernel32.dll", "hwnd", "OpenMutex", "int", 0x1F0001, "int", 1, "str", $szMutexName)
    Local $aGLE = DllCall("Kernel32.dll", "int", "GetLastError")
    If IsArray($hMutex) And $hMutex[0] Then
        DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hMutex[0])
    EndIf
    If IsArray($aGLE) And $aGLE[0] = 127 Then Return 1
    Return 0
EndFunc  ;==>_MutexExists

Func _ReleaseMutex($hMutex)
    Local $aRM = DllCall("kernel32.dll", "int", "ReleaseMutex", "hwnd", $hMutex)
    ConsoleWrite("!!!!" & _WinAPI_GetLastErrorMessage())
;ConsoleWrite("!!!!" & $aRM[0] & @CRLF)
    Local $aCH = DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hMutex)
    If (IsArray($aRM) And $aRM[0] > 0) And (IsArray($aCH) And $aCH[0] > 0) Then Return 1
    Return 0
EndFunc  ;==>_ReleaseMutex



Func _Escape()
    Exit
EndFunc  ;==>_Escape
Edited by simon387
Link to comment
Share on other sites

maybe I need to translate this in autoit

Private Sub CloseHandleEx(ByVal lPID As Long, ByVal lHandle As Long)
    Dim hProcess As Long
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, lPID)
    Call NtDuplicateObject(hProcess, lHandle, 0, ByVal 0, 0, 0, DUPLICATE_CLOSE_SOURCE)
    Call NtClose(hProcess)
End Sub
Link to comment
Share on other sites

Its frowned upon to bump your threads within 24hrs which is what you are doing. And you are more likely to piss people off than get their help.

You can use the edit button to add information.

Best of luck.

EDIT: ok its not your thread, but same dance.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...