Что нового

Пауза для всех функций в режиме EventMod

JimmyN

Новичок
Сообщения
20
Репутация
0
Требуется организовать паузу на все запущенные функции при нажатии кнопочки
Вот код
Код:
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\WoW_ico_64x64\Trade_Engineering.ico
#AutoIt3Wrapper_Res_Comment=Lazy Bot Relogger
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_Language=1049
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

AutoItSetOption("WinTitleMatchMode", 4)
;AutoItSetOption("ExpandVarStrings", 0)
AutoItSetOption("SendKeyDelay", 20)
AutoItSetOption("SendKeyDownDelay", 20)

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
Global $iRelogger
Global $iLogin
Global $iClicker
Global $StopClick
Global $Paused

$settings_ini = @ScriptDir & "\Settings.ini"
$char_ini = IniRead($settings_ini, "", "$char", "Персонаж")

#region Главное окно
$mainwindow = GUICreate($char_ini, 170, 245)

$settings = GUICtrlCreateButton("Настройки", 10, 155, 70)
$login = GUICtrlCreateButton("Логин", 10, 185, 70)
$relogger = GUICtrlCreateButton("Релоггер", 90, 185, 70)
$list = GUICtrlCreateList("", 2, 2, 166, 150)
$clicker = GUICtrlCreateButton("Кликер", 90, 155, 70)
$pause_button = GUICtrlCreateButton("Пауза", 10, 215, 150)

GUICtrlSetOnEvent($login, "Login_Event")
GUICtrlSetOnEvent($relogger, "Relogger_Event")
GUICtrlSetOnEvent($settings, "Settings")
GUICtrlSetOnEvent($clicker, "Clicker")
GUICtrlSetOnEvent($pause_button, "Pause_Event")
GUISetOnEvent($GUI_EVENT_CLOSE, "Exiting")
GUISetState(@SW_SHOW, $mainwindow)

#endregion Главное окно

#region Настройки
$setwindow = GUICreate("Настройки", 260, 300)


$acc_ini = IniRead($settings_ini, "", "$acc", "Логин")
$pass_ini = IniRead($settings_ini, "", "$pass", "Пароль")
$char_ini = IniRead($settings_ini, "", "$char", "Персонаж")
$bnet_ini = IniRead($settings_ini, "", "$bnet", "")
$wowpath_ini = IniRead($settings_ini, "", "$browse_wow", "Путь к WoW")
$botpath_ini = IniRead($settings_ini, "", "$browse_bot", "Путь к Боту")
$bnet_nini = IniRead($settings_ini, "", "$bnet_n", "")
$lvl_ini = IniRead($settings_ini, "", "$lvl", "lvl")

$acc_input = GUICtrlCreateInput($acc_ini, 20, 20, 200, 20)
$pass_input = GUICtrlCreateInput($pass_ini, 20, 50, 200, 20, $ES_PASSWORD)
$wowpath = GUICtrlCreateInput($wowpath_ini, 20, 100, 200, 20)
$browse_button1 = GUICtrlCreateButton("...", 230, 100, 20, 20)
$botpath = GUICtrlCreateInput($botpath_ini, 20, 130, 200, 20)
$browse_button2 = GUICtrlCreateButton("...", 230, 130, 20, 20)
$char_input = GUICtrlCreateInput($char_ini, 20, 180, 120, 20)
$bnet_check = GUICtrlCreateCheckbox("Battlenet", 20, 220)
$bnet_ncheck = GUICtrlCreateCombo("", 100, 220, 40, 20)
$save = GUICtrlCreateButton("Сохранить", 140, 260, 80, 20)
GUICtrlSetData(16, "1|2|3|4|5", $bnet_nini)
$lvl_input = GUICtrlCreateInput($lvl_ini, 170, 180, 50, 20)

GUICtrlSetState(15, $bnet_ini)
GUISetOnEvent($GUI_EVENT_CLOSE, "Exiting")
GUICtrlSetOnEvent($browse_button1, "WoW_path")
GUICtrlSetOnEvent($browse_button2, "Bot_path")
GUICtrlSetOnEvent($save, "Save")

#endregion Настройки

#region Кликер
$clickwindow = GUICreate("Кликер", 141, 70, 258, 130)

$key_ini = IniRead($settings_ini, "", "$key", "Кнопка")
$deley_ini = IniRead($settings_ini, "", "$deley", "Таймаут")

$key_input = GUICtrlCreateInput($key_ini, 10, 8, 50, 20)
$deley_input = GUICtrlCreateInput($deley_ini, 80, 8, 50, 20)
$start = GUICtrlCreateButton("Старт", 10, 40, 50, 20, $WS_GROUP)
$stop = GUICtrlCreateButton("Стоп", 80, 40, 50, 20, $WS_GROUP)
GUICtrlSetOnEvent($start, "Clicker_Event")
GUICtrlSetOnEvent($stop, "Clicker_Stop")
GUISetOnEvent($GUI_EVENT_CLOSE, "Exiting")
#endregion Кликер

#region Переменные
$acc = GUICtrlRead($acc_input)
$pass = GUICtrlRead($pass_input)
$char = GUICtrlRead($char_input)
$bnet = GUICtrlRead($bnet_check)
$browse_wow = GUICtrlRead($wowpath)
$browse_bot = GUICtrlRead($botpath)
$bnet_n = GUICtrlRead($bnet_ncheck)
$lvl = GUICtrlRead($lvl_input)
$winname = $acc
$str = StringLen($char)
$str2 = StringLeft($char, $str - 2)
$id = $str2 & " - " & $lvl
#endregion Переменные

Func WoW_path()
	$browse_wow = FileOpenDialog("Open", "C:\", "(*.exe)", 1)
	GUICtrlDelete($wowpath)
	$path_input = GUICtrlCreateInput($browse_wow, 20, 100, 200, 20)
EndFunc   ;==>WoW_path

Func Bot_path()
	$browse_bot = FileOpenDialog("Open", "C:\", "(*.exe)", 1)
	GUICtrlDelete($botpath)
	$path_input = GUICtrlCreateInput($browse_bot, 20, 130, 200, 20)
EndFunc   ;==>Bot_path

Func Save()
	$acc = GUICtrlRead($acc_input)
	$pass = GUICtrlRead($pass_input)
	$char = GUICtrlRead($char_input)
	$bnet = GUICtrlRead($bnet_check)
	$browse_wow = GUICtrlRead($wowpath)
	$browse_bot = GUICtrlRead($botpath)
	$bnet_n = GUICtrlRead($bnet_ncheck)
	$lvl = GUICtrlRead($lvl_input)
	$winname = $acc

	IniWrite($settings_ini, "", "$acc", $acc)
	IniWrite($settings_ini, "", "$pass", $pass)
	IniWrite($settings_ini, "", "$char", $char)
	IniWrite($settings_ini, "", "$bnet", $bnet)
	IniWrite($settings_ini, "", "$browse_wow", $browse_wow)
	IniWrite($settings_ini, "", "$browse_bot", $browse_bot)
	IniWrite($settings_ini, "", "$bnet_n", $bnet_n)
	IniWrite($settings_ini, "", "$lvl", $lvl)

	GUISetState(@SW_HIDE, $setwindow)

EndFunc   ;==>Save

Func Pause_Event()

EndFunc   ;==>Pause_Event


Func Settings()
	GUISwitch($setwindow)
	GUISetState(@SW_SHOW, $setwindow)
EndFunc   ;==>Settings

Func Clicker()
	GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Кликер запущен")
	GUISwitch($clickwindow)
	GUISetState(@SW_SHOW, $clickwindow)
EndFunc   ;==>Clicker

Func Clicker_Event()
	$key = GUICtrlRead($key_input)
	GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Жмём" & " < " & $key & " >")
	$iClicker = 1
EndFunc   ;==>Clicker_Event

Func Clicker_Stop()
	$key = GUICtrlRead($key_input)
	GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Не жмем" & " < " & $key & " >")
	$StopClick = 1
EndFunc   ;==>Clicker_Stop

Func Clicker_func()
	$key = GUICtrlRead($key_input)
	$deley = GUICtrlRead($deley_input)
	IniWrite($settings_ini, "", "$key", $key)
	IniWrite($settings_ini, "", "$deley", $deley)
	While $StopClick <> 1
		ControlSend($winname, "", "", $key)
		Sleep($deley)
	WEnd
EndFunc   ;==>Clicker_func

Func Exiting()
	If @GUI_WinHandle = $mainwindow Then
		GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Выход")
		Sleep(300)
		Exit (0)
	ElseIf @GUI_WinHandle = $clickwindow Then
		GUISetState(@SW_HIDE, $clickwindow)
	ElseIf @GUI_WinHandle = $setwindow Then
		GUISetState(@SW_HIDE, $setwindow)

	EndIf
EndFunc   ;==>Exiting

Func Login_Event()
	$iLogin = 1
EndFunc   ;==>Login_Event

Func Login()
	$Paused = Not $Paused
	GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Запуск WoW")
	Run($browse_wow)
	WinWait("World of Warcraft")
	Sleep(5000)
	WinSetTitle("World of Warcraft", "", $winname)
	Sleep(100)
	WinMove($winname, "", 0, 0, 328, 270)
	Sleep(5000)
	GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Логин")
	Sleep(1000)
	ClipPut($acc)
	Sleep(500)
	ControlSend($winname, "", 0, "{CTRLDOWN}v{CTRLUP}")
	Sleep(1000)
	ControlSend($winname, "", "", "{TAB}")
	Sleep(1000)
	ClipPut($pass)
	Sleep(500)
	ControlSend($winname, "", 0, "{CTRLDOWN}v{CTRLUP}")
	Sleep(1000)
	ControlSend($winname, "", "", "{ENTER}")
	Sleep(3000)

	If $bnet = $GUI_CHECKED Then
		If $bnet_n = 1 Then
			ControlSend($winname, "", "", "{ENTER}")
			Sleep(3000)
		ElseIf $bnet_n = 2 Then
			ControlSend($winname, "", "", "{DOWN}")
			Sleep(1000)
			ControlSend($winname, "", "", "{ENTER}")
		ElseIf $bnet_n = 3 Then
			ControlSend($winname, "", "", "{DOWN 2}")
			Sleep(1000)
			ControlSend($winname, "", "", "{ENTER}")
		ElseIf $bnet_n = 4 Then
			ControlSend($winname, "", "", "{DOWN 3}")
			Sleep(1000)
			ControlSend($winname, "", "", "{ENTER}")
		ElseIf $bnet_n = 5 Then
			ControlSend($winname, "", "", "{DOWN 4}")
			Sleep(1000)
			ControlSend($winname, "", "", "{ENTER}")
		EndIf
	EndIf

	Sleep(10000)
	GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Загрузка персонажа")
	Sleep(1000)
	ControlSend($winname, "", "", "{ENTER}")
	Sleep(30000)
	GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Запуск бота")
	Sleep(1000)
	Run($browse_bot)
	;ControlClick("Select process", "Attach", "[CLASS:WindowsForms10.Window.8.app.0.378734a; INSTANCE:2]","left")
	;Sleep(5000)
	GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Выберите процесс")
	WinWait("Ready", $char)
	Sleep(5000)
	$title = WinGetHandle("[CLASS:WindowsForms10.Window.8.app.0.378734a]", $id)
	Sleep(1000)
	ControlClick($title, "Start botting", "[CLASS:WindowsForms10.Window.8.app.0.378734a; INSTANCE:13]", "left")
	Sleep(1000)
	GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Готово")
	Sleep(1000)

EndFunc   ;==>Login

Func Relogger_Event()
	$iRelogger = 1
EndFunc   ;==>Relogger_Event

Func Relogger()

	GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Релоггер запущен")

	While 1
		Do
			Sleep(100)
			$var = Ping("www.mail.ru", 1000)
		Until $var

		$title2 = WinGetHandle("[CLASS:WindowsForms10.Window.8.app.0.378734a]", $id)
		$line = ControlCommand($title2, "", "[CLASS:WindowsForms10.RichEdit20W.app.0.378734a; INSTANCE:1]", "GetLineCount", "")
		$txt = ControlCommand($title2, "", "[CLASS:WindowsForms10.RichEdit20W.app.0.378734a; INSTANCE:1]", "GetLine", $line - 1)
		$result = StringRegExp($txt, "Bot stopped", 0)
		$result2 = StringRegExp($txt, "Please ress before starting the bot", 0)
		$result3 = StringRegExp($txt, "this is not optional!", 0)
		$result4 = StringRegExp($txt, "Please enter the world", 0)
		$result5 = StringRegExp($txt, "Attached", 0)
		$result6 = StringRegExp($txt, "Please login", 0)

		If $result3 = 1 Then
			$title2 = WinGetHandle("[CLASS:WindowsForms10.Window.8.app.0.378734a]", $id)
			ControlClick($title2, "Stop botting", "[CLASS:WindowsForms10.Window.8.app.0.378734a; INSTANCE:13]", "left")
			GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Перезапуск")
			ControlClick($title2, "Start botting", "[CLASS:WindowsForms10.Window.8.app.0.378734a; INSTANCE:13]", "left")
		ElseIf $result = 1 Then
			$title2 = WinGetHandle("[CLASS:WindowsForms10.Window.8.app.0.378734a]", $id)
			GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Запуск бота")
			ControlClick($title2, "Start botting", "[CLASS:WindowsForms10.Window.8.app.0.378734a; INSTANCE:13]", "left")
		ElseIf $result4 = 1 Or $result6 = 1 Then
			$title2 = WinGetHandle("[CLASS:WindowsForms10.Window.8.app.0.378734a]", $id)
			GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Дисконект")
			Sleep(5000)
			ControlSend($winname, "", "", "{ENTER}")
			Sleep(1000)
			ControlSend($winname, "", "", "{Backspace 50}")
			Sleep(5000)
			GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Логин")
			Sleep(1000)
			ClipPut($acc)
			Sleep(500)
			ControlSend($winname, "", 0, "{CTRLDOWN}v{CTRLUP}")
			Sleep(1000)
			ControlSend($winname, "", "", "{TAB}")
			Sleep(1000)
			ClipPut($pass)
			Sleep(500)
			ControlSend($winname, "", 0, "{CTRLDOWN}v{CTRLUP}")
			Sleep(1000)

			If $bnet = $GUI_CHECKED Then
				If $bnet_n = 1 Then
					ControlSend($winname, "", "", "{ENTER}")
					Sleep(3000)
				ElseIf $bnet_n = 2 Then
					ControlSend($winname, "", "", "{DOWN}")
					Sleep(1000)
					ControlSend($winname, "", "", "{ENTER}")
				ElseIf $bnet_n = 3 Then
					ControlSend($winname, "", "", "{DOWN 2}")
					Sleep(1000)
					ControlSend($winname, "", "", "{ENTER}")
				ElseIf $bnet_n = 4 Then
					ControlSend($winname, "", "", "{DOWN 3}")
					Sleep(1000)
					ControlSend($winname, "", "", "{ENTER}")
				ElseIf $bnet_n = 5 Then
					ControlSend($winname, "", "", "{DOWN 4}")
					Sleep(1000)
					ControlSend($winname, "", "", "{ENTER}")
				EndIf
			EndIf

			ControlSend($winname, "", "", "{ENTER}")
			Sleep(10000)
			GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Загрузка персонажа")
			Sleep(1000)
			ControlSend($winname, "", "", "{ENTER}")
			Sleep(30000)

		ElseIf $result5 = 1 Then
			$title2 = WinGetHandle("[CLASS:WindowsForms10.Window.8.app.0.378734a]", $id)
			GUICtrlSetData(6, @HOUR & ":" & @MIN & ":" & @SEC & "   Запуск бота")
			ControlClick($title2, "Start botting", "[CLASS:WindowsForms10.Window.8.app.0.378734a; INSTANCE:13]", "left")
		EndIf
	WEnd

EndFunc   ;==>Relogger

While 1
	Sleep(100)

	If $iRelogger Then
		$iRelogger = 0
		Relogger()
	ElseIf $iLogin Then
		$iLogin = 0
		Login()
	ElseIf $iClicker Then
		$iClicker = 0
		Clicker_func()
	EndIf

WEnd

Заранее благодарю)
 

edward_freedom

Осваивающий
Сообщения
200
Репутация
44
Может вот так...

Код:
Global $Paused
HotKeySet("{PAUSE}", "TogglePause") 
Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip("Script is Paused")
WEnd
ToolTip("")
EndFunc
 
Автор
JimmyN

JimmyN

Новичок
Сообщения
20
Репутация
0
да так работает но мне в GUI нужно на кнопочку назначить, а если такую функцию назначить то почему то не работает...
 

tech-gs

Знающий
Сообщения
54
Репутация
5
Приведенные выше примеры приостанавливают работу скрипта. Но запущенные из скрипта процессы будут продолжать работать. Привожу пример приостановки всех запущенных из скрипта дочерних процессов.
Для профессионалов AutoIt: если будут замечены какие-либо неточности или несуразности, прошу сообщить.

Код:
#include <GUIConstantsEx.au3>

$Archiver = @ProgramFilesDir & '\7-Zip\7z.exe' ; Упаковщик
$FilesToArc = @ProgramFilesDir & '\*.*' ; Файлы для архивирования
$ArcFile = @TempDir & '\test.7z' ; Файл создаваемого архива
$ArcFilesCmd = '"' & $Archiver & '" a "' & $ArcFile & '" -t7z -m0=BCJ -m1=LZMA:d=26 -mx=9 -mhc=on -ms=on -mmt=on "' & $FilesToArc & '"'	; Команда упаковки файлов
$ArcCmd = '"' & @COMSPEC & '" /v:on /c "@echo off & title Create Archive ' & $ArcFile & ' & echo. & ' & $ArcFilesCmd & ' & echo. & echo Pause 10 sec & ping -n 10 localhost > nul & exit "' ; Команда CMD-сессии
FileDelete($ArcFile)

$Pause = 0

$Form1 = GUICreate("Test SuspendProcess", 370, 100, -1, -1)
$Button1 = GUICtrlCreateButton("Arc ProgramFilesDir", 45, 30, 150, 24)
GUICtrlSetTip($Button1, 'Создание архива папки "' & $FilesToArc & '" как "' & $ArcFile & '"')
$Button2 = GUICtrlCreateButton("Pause", 230, 30, 90, 24)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
			FileDelete($ArcFile)
            Exit
        Case $button1
			FileDelete($ArcFile)
			If FileExists($Archiver) Then
				Run($ArcCmd, '', @SW_SHOW)
			Else
				MsgBox(64, 'Info', 'Архиватор "' & $Archiver & '" не найден.')
			EndIf
        Case $button2
			If $Pause = 0 Then
				$Pause = 1
				GUICtrlSetData($button2, 'Resume')
			Else
				$Pause = 0
				GUICtrlSetData($button2, 'Pause')
			EndIf
			__WinAPI_SuspendProcess(@AutoItPID, $Pause=1, False)
    EndSwitch
WEnd


Func __WinAPI_SuspendProcess($iPID, $bSuspend=True, $bSuspendParent=False)
	;Write_Console_Msg('', '+', "__WinAPI_SuspendProcess(" & $iPID & ", " & $bSuspend & ", " & $bSuspendParent & ") -> Старт", @CRLF, @ScriptLineNumber)
Local $ret = ProcessExists($iPID)

	If Not $ret Then
		Write_Console_Msg(@CRLF, '+', "__WinAPI_SuspendProcess() -> WARNING: Процесс PID=" & $iPID & " не существует", @CRLF, @ScriptLineNumber)
		Return SetError(1, 0, 0)
	Else
		$iPID = $ret
	EndIf

Local $aNtSuspResumProc
Local $ah_OpProcess = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1F0FFF, 'int', 0, 'int', $iPID)
	;Write_Console_Msg('', '+', "__WinAPI_SuspendProcess() -> Процесс " & $iPID & " открыт (DllCall('kernel32.dll', ...):  bSuspend=" & $bSuspend & ", bSuspendParent=" & $bSuspendParent, @CRLF, @ScriptLineNumber)

	If $bSuspend = False Then
		;Write_Console_Msg('', '+', "__WinAPI_SuspendProcess() -> DllCall('ntdll.dll', ..., 'NtResumeProcess', ...) - Старт", @CRLF, @ScriptLineNumber)
		$aNtSuspResumProc = DllCall("ntdll.dll", "int", "NtResumeProcess", "int", $ah_OpProcess[0])
		If IsArray($aNtSuspResumProc) Then
			Write_Console_Msg("", '+', "__WinAPI_SuspendProcess():   Процесс  hWnd=" & __ProcessGetWindow($iPID, 1) & "  PID=" & $iPID & "  Title='" & __ProcessGetWindow($iPID, 0) & "'  - Возобновлен", @CRLF, @ScriptLineNumber)
		Else
			Write_Console_Msg('', '!', "__WinAPI_SuspendProcess() -> WARNING: Ошибка возобновления процесса " & $ah_OpProcess[0] & " (DllCall('ntdll.dll', ...)", @CRLF, @ScriptLineNumber)
		EndIf
	ElseIf $bSuspendParent = True Then
		;Write_Console_Msg('', '+', "__WinAPI_SuspendProcess() -> DllCall('ntdll.dll', ..., 'NtSuspendProcess', ...) - Старт", @CRLF, @ScriptLineNumber)
		$aNtSuspResumProc = DllCall("ntdll.dll", "int", "NtSuspendProcess", "int", $ah_OpProcess[0])
		If IsArray($aNtSuspResumProc) Then
			Write_Console_Msg("", '+', "__WinAPI_SuspendProcess(" & $iPID & ", " & $bSuspend & "):   Процесс  hWnd=" & __ProcessGetWindow($iPID, 1) & "  PID=" & $iPID & "  Title='" & __ProcessGetWindow($iPID, 0) & "'  - Приостановлен", @CRLF, @ScriptLineNumber)
		Else
			Write_Console_Msg('', '!', "__WinAPI_SuspendProcess() -> WARNING: Ошибка приостановки процесса " & $ah_OpProcess[0] & " (DllCall('ntdll.dll', ...)", @CRLF, @ScriptLineNumber)
		EndIf
	Else
		Write_Console_Msg("", '+', "__WinAPI_SuspendProcess():   Процесс  hWnd=" & __ProcessGetWindow($iPID, 1) & "  PID=" & $iPID & "  Title='" & __ProcessGetWindow($iPID, 0) & "'  - Приостановка пропущена (родитель)", @CRLF, @ScriptLineNumber)
	EndIf

	DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $ah_OpProcess)
	;Write_Console_Msg('', '+', "__WinAPI_SuspendProcess() -> Процесс " & $iPID & " закрыт (DllCall('kernel32.dll', ...)", @CRLF, @ScriptLineNumber)

	If IsArray($aNtSuspResumProc)=True Or $bSuspendParent=False Then
Local $ProcList = ProcessList()	; Возвращает Name, PID
		For $ret = 1 To $ProcList[0][0] ; Поиск дочерних процессов для приостановки
			;Write_Console_Msg("", '+', @TAB & "ProcessList():" & @TAB & "hWnd=" & __ProcessGetWindow($ProcList[$ret][1], 1) & StringLeft(@TAB, 1*(String(__ProcessGetWindow($ProcList[$ret][1], 1))="")) & @TAB & "  PID=" & $ProcList[$ret][1] & " " & @TAB & "Name=" & $ProcList[$ret][0] & StringLeft(@TAB & @TAB & @TAB & @TAB & @TAB, 5-Int((StringLen($ProcList[$ret][0])+5)/8)) & "Title=" & __ProcessGetWindow($ProcList[$ret][1], 0), @CRLF, @ScriptLineNumber)
			If __WinAPI_ProcessGetParent($ProcList[$ret][1]) = $iPID Then
				;Write_Console_Msg("", '>', @TAB & "Процесс PID=" & $ProcList[$ret][1] & " Name=" & $ProcList[$ret][0] & " - Родитель процесса PID=" & $iPID & ".  Вызов рекурсии __WinAPI_SuspendProcess().", @CRLF, @ScriptLineNumber)
				__WinAPI_SuspendProcess($ProcList[$ret][1], $bSuspend, True)
			EndIf
		Next
		Return 1
	EndIf

	;Write_Console_Msg(@CRLF, '!', "__WinAPI_SuspendProcess(" & $iPID & ", " & $bSuspend & ") - ERROR 2", @CRLF, @ScriptLineNumber)
	Return SetError(2, 0, 0)
EndFunc

Func __WinAPI_ProcessGetParent($i_Pid)
	Local Const $TH32CS_SNAPPROCESS = 0x00000002

	Local $a_tool_help = DllCall("Kernel32.dll", "long", "CreateToolhelp32Snapshot", "int", $TH32CS_SNAPPROCESS, "int", 0)
	If IsArray($a_tool_help) = 0 Or $a_tool_help[0] = -1 Then Return SetError(1, 0, $i_Pid)

	Local $tagPROCESSENTRY32 = DllStructCreate( _
			"dword dwsize;" & _
			"dword cntUsage;" & _
			"dword th32ProcessID;" & _
			"uint th32DefaultHeapID;" & _
			"dword th32ModuleID;" & _
			"dword cntThreads;" & _
			"dword th32ParentProcessID;" & _
			"long pcPriClassBase;" & _
			"dword dwFlags;" & _
			"char szExeFile[260]")

	DllStructSetData($tagPROCESSENTRY32, 1, DllStructGetSize($tagPROCESSENTRY32))

	Local $p_PROCESSENTRY32 = DllStructGetPtr($tagPROCESSENTRY32)

	Local $a_pfirst = DllCall("Kernel32.dll", "int", "Process32First", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32)
	If IsArray($a_pfirst) = 0 Then Return SetError(2, 0, $i_Pid)

	Local $a_pnext, $i_return = 0

	If DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") = $i_Pid Then
		$i_return = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID")
		DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0])

		If $i_return Then Return $i_return
		Return $i_Pid
	EndIf

	While 1
		$a_pnext = DllCall("Kernel32.dll", "int", "Process32Next", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32)
		If IsArray($a_pnext) And $a_pnext[0] = 0 Then ExitLoop
		If DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") = $i_Pid Then
			$i_return = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID")
			If $i_return Then ExitLoop
			$i_return = $i_Pid
			ExitLoop
		EndIf
	WEnd

	If $i_return = "" Then $i_return = $i_Pid

	DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0])
	Return $i_return
EndFunc

Func __ProcessGetWindow($iPID, $iRet=1) ; функция получения заголовка и указателя окна по его PID
; $iRet - тип возвращаемых данных: 0 - Title, 1 - hWnd, иначе - массив Title,hWnd
	;Write_Console_Msg('', '+', "__ProcessGetWindow(" & $iPID & ", " & $iRet & ") -> Старт", @CRLF, @ScriptLineNumber)
Local $aWinList = WinList()
Local $i=0, $aRet[2]
    If IsString($iPID) Then $iPID = ProcessExists($iPID)
    For $i = 1 To UBound($aWinList)-1
        If WinGetProcess($aWinList[$i][1]) = $iPID Then
            $aRet[0] = $aWinList[$i][0] ; Title
            $aRet[1] = $aWinList[$i][1] ; WinHandle
			;Write_Console_Msg('', '+', "__ProcessGetWindow() -> aRet[0]=" & $aRet[0] & ", aRet[1]=" & $aRet[1], @CRLF, @ScriptLineNumber)
            If $iRet = 0 Then Return $aRet[0]
            If $iRet = 1 Then Return $aRet[1]
            Return $aRet
        EndIf
    Next
	;Write_Console_Msg('', '+', "__ProcessGetWindow() -> ОШИБКА: aRet=" & $aRet, @CRLF, @ScriptLineNumber)
    Return SetError(1, 0, $aRet)
EndFunc

Func Write_Console_Msg($Left, $symbol, $text, $Right = @CRLF, $ScrLN = -1, $Time = 1)
	If $ScrLN <> -1 Then $text = StringLeft("      ", 6-StringLen($ScrLN)) & $ScrLN & @TAB & $text
	If $Time Then $text = @HOUR & ":" & @MIN & ":" & @SEC & "  " & $text
	If $symbol = ">" Then
		$text = $symbol & "  " & $text
	ElseIf $symbol <> "" Then
		$text = $symbol & "> " & $text
	EndIf
	ConsoleWrite($Left & $text & $Right)
EndFunc
 

Yashied

Модератор
Команда форума
Глобальный модератор
Сообщения
5 379
Репутация
2 711
Во-первых, это будет работать только с правами администратора. А во-вторых, остановка таким вот способом какого-либо процесса может быть чревата появлением серьезных ошибок.
 
Верх