Created
July 20, 2020 14:17
-
-
Save fiddyschmitt/ba2ddcd0786fd610368ba24038765fe1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Region ;**** Directives created by AutoIt3Wrapper_GUI **** | |
#AutoIt3Wrapper_Change2CUI=y | |
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** | |
#include <AutoItConstants.au3> | |
#include <StringConstants.au3> | |
#include <Array.au3> | |
Local $processOrPid | |
Local $mutantName | |
If $CmdLine[0] = 2 Then | |
$processOrPid = $CmdLine[1] ;eg. notepad.exe or 20123 | |
$mutantName = $CmdLine[2] ;\Sessions\1\BaseNamedObjects\SessionImmersiveColorMutex | |
Else | |
ConsoleWrite("Invalid arguments. Please provide two arguments: [process name|pid] mutexName" & @CRLF & "Example: " & @CRLF & @ScriptName & " notepad.exe \Sessions\1\BaseNamedObjects\SessionImmersiveColorMutex") | |
Exit | |
EndIf | |
$listHandlesCommand = "handle.exe -p " & $processOrPid & " -nobanner -a " & $mutantName | |
Local $listHandlePID = Run($listHandlesCommand, @ScriptDir, @SW_HIDE, $STDOUT_CHILD) | |
ProcessWaitClose($listHandlePID) | |
Local $sOutput = StdoutRead($listHandlePID) | |
;~ ConsoleWrite($sOutput & @CRLF) | |
$lines = StringSplit($sOutput, @CRLF, $STR_ENTIRESPLIT + $STR_NOCOUNT) | |
;~ _ArrayDisplay($lines) | |
;Example: | |
;notepad.exe pid: 24900 type: Mutant 224: \Sessions\1\BaseNamedObjects\SessionImmersiveColorMutex | |
For $line In $lines | |
$line = StringStripWS($line, $STR_STRIPLEADING + $STR_STRIPTRAILING) | |
;~ ConsoleWrite($line & @CRLF) | |
If StringRegExp($line, "pid:") Then | |
$pidMatches = StringRegExp($line, "pid: (\d*)", $STR_REGEXPARRAYGLOBALMATCH) | |
$pid = $pidMatches[0] | |
$mutantMatches = StringRegExp($line, "(\w*):", $STR_REGEXPARRAYGLOBALMATCH) | |
$mutantHandle = $mutantMatches[2] | |
ConsoleWrite("Closing Mutant Handle " & $mutantHandle & " in Process ID " & $pid & @CRLF) | |
;Example | |
;handle.exe -p 40012 -c 21C -nobanner -y | |
$closeHandleCommand = "handle.exe -p " & $pid & " -c " & $mutantHandle & " -nobanner -y" | |
RunWait($closeHandleCommand, @ScriptDir, @SW_HIDE) | |
EndIf | |
Next |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment