Opt('MustDeclareVars', 1)
Opt('TrayMenuMode', 1)
Global $aProcess, $sFile, $j = 0, $aAutoIt[$j + 1], $sTitle = 'Поиск процессов AutoIt', _
$sMessage = 'Нет ни одного процесса AutoIt.'
If WinExists(@ScriptName) Then Exit
AutoItWinSetTitle(@ScriptName)
$aProcess = ProcessList()
If Not @error Then
For $i = 1 To $aProcess[0][0]
$sFile = _WinAPI_GetProcessFileName($aProcess[$i][1])
If _FileIsAutoItScript($sFile) And $sFile <> @ScriptFullPath Then
$j += 1
ReDim $aAutoIt[$j + 1]
$aAutoIt[$j] = $sFile
EndIf
Next
If $j Then
$sMessage = 'Найдено процессов AutoIt: ' & $j & @CRLF & @CRLF
For $n = 1 To $j
$sMessage &= $aAutoIt[$n] & @CRLF
Next
EndIf
MsgBox(64, $sTitle, $sMessage)
Else
MsgBox(16, $sTitle, 'Ошибка.')
EndIf
Func _FileIsAutoItScript($sExeFile)
Local $sSignature = BinaryToString('0xA3484BBE986C4AA9994C530A86D6487D')
Local $sRead = FileRead($sExeFile)
Return StringInStr($sRead, $sSignature) > 0
EndFunc ;==>_FileIsAutoItScript
Func _WinAPI_GetCurrentProcessID()
Local $aResult = DllCall('kernel32.dll', 'dword', 'GetCurrentProcessId')
If @error Then Return SetError(@error, @extended, 0)
Return $aResult[0]
EndFunc ;==>_WinAPI_GetCurrentProcessID
Func _WinAPI_CloseHandle($hObject)
Local $aResult = DllCall('kernel32.dll', 'bool', 'CloseHandle', 'handle', $hObject)
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0]
EndFunc ;==>_WinAPI_CloseHandle
Func _WinAPI_GetProcessFileName($PID = 0)
If Not $PID Then
$PID = _WinAPI_GetCurrentProcessID()
If Not $PID Then
Return SetError(1, 0, '')
EndIf
EndIf
Local $hProcess = DllCall('kernel32.dll', 'ptr', 'OpenProcess', 'dword', 0x00000410, 'int', 0, 'dword', $PID)
If (@error) Or (Not $hProcess[0]) Then
Return SetError(1, 0, '')
EndIf
Local $tPath = DllStructCreate('wchar[1024]')
Local $Ret = DllCall(@SystemDir & '\psapi.dll', 'int', 'GetModuleFileNameExW', 'ptr', $hProcess[0], 'ptr', 0, 'ptr', DllStructGetPtr($tPath), 'int', 1024)
If (@error) Or (Not $Ret[0]) Then
$Ret = 0
EndIf
_WinAPI_CloseHandle($hProcess[0])
If Not IsArray($Ret) Then
Return SetError(1, 0, '')
EndIf
Return DllStructGetData($tPath, 1)
EndFunc ;==>_WinAPI_GetProcessFileName