<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Process Exist]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=6067&amp;type=atom" />
	<updated>2011-07-28T16:44:59Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=6067</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Process Exist]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=50250#p50250" />
			<content type="html"><![CDATA[<p>Писал такой скрипт для себя.<br />Запускает Программу №2, если запускается Программа №1.<br />Описание в самом скрипте.<br /></p><div class="codebox"><pre><code>;~ *** Скрипт запускает Tool_2_ при старте Tool_1_
;~ *** Опционально следит за состоянием Tool_2_ и не дает ему закрыться во время работы Tool_1_
;~ *** Путь к Tool_2_ настраивается через переменную Tool_2__Path

;~ *** НАСТРОЙКИ

;~ Если перемнная Tool_2__Guard=1, скрипт следит за состоянием Tool_2_.
;~ Если по каким-либо причинам Tool_2_ закрывается, то скрипт запускает его вновь
;~ Т.е. скрипт не будет давать закрываться Tool_2_ во время открытого Tool_1_.
;~ Если перемнная Tool_2__Guard=0, то Tool_2_ будет запускаться только при старте Tool_1_.
;~ Во время работы Tool_1_, скрипт не будет вновь запускать Tool_2_, если он закроется.
   Tool_2__Guard:=1

;~ Если переменная Close_Tool_2_=1, то Tool_2_ будет закрываться вместе с Tool_1_
   Close_Tool_2_:=1

;~ Раскомментируйте следующую строку, что бы убрать иконку из трея
;~ В этом случае скрипт можно будет завершить через диспетчер задач
   ;~ #NoTrayIcon

;~ Укажите путь к Tool_2_
   Tool_2__Path:=&quot;C:\Tool_2_.exe&quot;

;~ Имя процесса Tool_2_
   Tool_2_:=&quot;Tool_2_.exe&quot;

; Имя процесса Tool_1_
Tool_1_:=&quot;Tool_1_.exe&quot; 

;~ ДАЛЕЕ НЕ РЕДАКТИРОВАТЬ

#SingleInstance, force ; перезапускать скрипт, если он уже запущен
SetBatchLines, -1 ; быстрое выполнение команд
DetectHiddenWindows, on ; обнаружение скрытых окон

Path:=RegExReplace(Tool_2__Path, &quot;(.*)\\(.*)&quot;, &quot;$1&quot;)
Target:=RegExReplace(Tool_2__Path, &quot;(.*)\\(.*)&quot;, &quot;$2&quot;)
If Tool_2__Guard ; если надо следить за состоянием процесса Tool_2_
   SetTimer, Tool_2__Guard, 2000 ; запускаем таймер каждые 2 сек


Loop ; зацикливаем скрипт
{
   Process, wait, %Tool_1_% ; ждем появления процесса Tool_1_
   
   Process, Exist, %Tool_2_% ; проверяем процесс Tool_2_
   If !ErrorLevel ; если не запущен
      Run % &quot;&quot; Target &quot;&quot;, %Path% ; запускаем
   
   Process, WaitClose, %Tool_1_% ; ждем закрытия процесса Tool_1_
   
   If !Close_Tool_2_ ; если не разрешено закрвать Tool_2_ при выходе из Tool_1_
      continue ; не выполняем остальные команды
   
   Process, Exist, %Tool_2_% ; проверяем состояние Tool_2_
   If (PID:=ErrorLevel) ; если запущен, записываем его PID
      Loop ; в цикле ждем закрытия Tool_2_ (для надежного закрытия Tool_2_, бывает не закрывается)
      {
         WinKill, ahk_pid %PID% ; закрываем Tool_2_
         WinWaitClose, ahk_pid %PID%,, 1 ; ждем 1 сек
         If !ErrorLevel ; если Tool_2_ закрыт
            break ; выходим из цикла
      }
}


Tool_2__Guard: ; таймер
   Process, Exist, %Tool_1_% ; проверяем состояние Tool_1_
   If !ErrorLevel ; если не запущен
      return ; пропускаем остальные действия
   
   Process, Exist, %Tool_2_% ; проверяем состояние Tool_2_
   If !ErrorLevel ; если на запущен
      Run % &quot;&quot; Target &quot;&quot;, %Path% ; запускаем
return</code></pre></div>]]></content>
			<author>
				<name><![CDATA[InFlames]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24849</uri>
			</author>
			<updated>2011-07-28T16:44:59Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=50250#p50250</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Process Exist]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=50249#p50249" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p><a href="http://www.script-coding.com/AutoHotkey/Variables.1.0.46.07.html#3">Цитата</a>:<br />Логическое НЕ (!). Если операнд пуст или равен 0</p></blockquote></div>]]></content>
			<author>
				<name><![CDATA[Grey]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=25792</uri>
			</author>
			<updated>2011-07-28T16:40:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=50249#p50249</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Process Exist]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=50248#p50248" />
			<content type="html"><![CDATA[<p>А можно ссылку где это можно почитать? А то я или не внимательно читал или не видел этого еще.</p>]]></content>
			<author>
				<name><![CDATA[DaVinchi]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26386</uri>
			</author>
			<updated>2011-07-28T16:33:27Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=50248#p50248</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Process Exist]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=50247#p50247" />
			<content type="html"><![CDATA[<p><span style="color: Green"><strong>DaVinchi</strong>, избегайте излишнего цитирования. Я поправил Ваш пост.</span></p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-07-28T16:21:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=50247#p50247</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Process Exist]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=50246#p50246" />
			<content type="html"><![CDATA[<p>Восклицательный знак - это логическое отрицание, не так ли?</p>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2011-07-28T16:19:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=50246#p50246</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Process Exist]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=50244#p50244" />
			<content type="html"><![CDATA[<p>Прекрасно работает. Только вот я не пойму почему восклицательный знак и нет равенства?</p>]]></content>
			<author>
				<name><![CDATA[DaVinchi]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26386</uri>
			</author>
			<updated>2011-07-28T15:45:15Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=50244#p50244</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Process Exist]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=50242#p50242" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>Loop
   {
      Process, Exist, 1.exe
         If !ErrorLevel
            {
               Run, %A_ScriptDir%\1.exe
               Sleep, 5000
            }
         Else
            Sleep, 5000
   }
Return</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Grey]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=25792</uri>
			</author>
			<updated>2011-07-28T15:08:43Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=50242#p50242</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Process Exist]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=50240#p50240" />
			<content type="html"><![CDATA[<p>А какие ошибки? В чем не корректность работы скрипта?</p>]]></content>
			<author>
				<name><![CDATA[Mikki]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=5905</uri>
			</author>
			<updated>2011-07-28T14:25:46Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=50240#p50240</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Process Exist]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=50239#p50239" />
			<content type="html"><![CDATA[<p>В общем то надумал создать скрипт контроля процесса. Порылся поглядел команды и нашел Process.<br />И вот тут появились вопросы, что я не так делаю?<br />Вот код который я надумал:<br /></p><div class="codebox"><pre><code>Loop,
{
Process, Exist, 1.exe
	if ErrorLevel=0
	{
	Sleep, 5000
	}
	else
	{
	run, %A_ScriptDir%\1.exe
	Sleep, 5000
	}
}
return,</code></pre></div><p>Суть следующая: Проверяется существует ли процесс или нет. Если нет - запускает его. Но видимо я не правильно понял и что то не так намудрил=(</p>]]></content>
			<author>
				<name><![CDATA[DaVinchi]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26386</uri>
			</author>
			<updated>2011-07-28T14:17:33Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=50239#p50239</id>
		</entry>
</feed>
