<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: #SingleInstance Force как определить был ли запущен скрипт]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=11045&amp;type=atom" />
	<updated>2015-11-06T10:42:38Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=11045</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: #SingleInstance Force как определить был ли запущен скрипт]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=98713#p98713" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>#SingleInstance Off
Gui, Show, w250 h0 ,Gui для наглядности
Process, priority, , Realtime
Pid1 := ErrorLevel

Loop
{
ProcessName := &quot;AutoHotkey.exe&quot;
for Process in ComObjGet(&quot;winmgmts:&quot;).ExecQuery(&quot;Select * from Win32_Process Where Name = &#039;&quot; ProcessName &quot;&#039;&quot;)
if (InStr(Process.CommandLine,A_ScriptName) &amp;&amp; Process.ProcessId!=%Pid1%)
{
    ProcessId := Process.ProcessId
    SearchProcess := Process.CommandLine
        If ProcessId-Pid1=0
        {
            Goto ExitLoop
        }
        Else
        {
            OldPar := &quot;1&quot;
            RegExMatch(SearchProcess, A_ScriptName &quot;(.*)&quot;, OldPar)
            StringReplace,OldPar,OldPar,%A_ScriptName%,,All
            Process.Terminate
        }
}
}
ExitLoop:
If OldPar
MsgBox Скрипт перезапущен `n %OldPar%
Else
MsgBox Скрипт запущен в первые
Return

Escape::
GuiClose:
ExitApp</code></pre></div><p>Спасибо, теперь работает как задумано.</p>]]></content>
			<author>
				<name><![CDATA[Nikva]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27416</uri>
			</author>
			<updated>2015-11-06T10:42:38Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=98713#p98713</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: #SingleInstance Force как определить был ли запущен скрипт]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=98710#p98710" />
			<content type="html"><![CDATA[<p><a href="http://forum.script-coding.com/viewtopic.php?pid=77643#p77643">Ссылка.</a><br /></p><div class="codebox"><pre><code>ProcessName := &quot;AutoHotkey.exe&quot;
Processes := ComObjGet(&quot;winmgmts:&quot;).ExecQuery(&quot;Select * from Win32_Process Where Name = &#039;&quot; ProcessName &quot;&#039;&quot;)
</code></pre></div><p><span style="color: #eeeeee"><a href="https://www.google.ru/search?newwindow=1&amp;es_sm=122&amp;q=site%3Ahttp%3A%2F%2Fforum.script-coding.com%2F+ahk+ComObjGet%28%22winmgmts%3A%22%29&amp;oq=site%3Ahttp%3A%2F%2Fforum.script-coding.com%2F+ahk+ComObjGet%28%22winmgmts%3A%22%29&amp;gs_l=serp.3...22066.25204.0.25609.7.7.0.0.0.0.94.639.7.7.0....0...1c.1.64.serp..7.0.0.mt2IzeSQfz0">Как можно пользоваться поиском.</a></span></p>]]></content>
			<author>
				<name><![CDATA[Alectric]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26027</uri>
			</author>
			<updated>2015-11-06T09:50:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=98710#p98710</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: #SingleInstance Force как определить был ли запущен скрипт]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=98707#p98707" />
			<content type="html"><![CDATA[<p>На форуме нашёл похожую проблему и её решение от: <a href="http://script-coding.com/forum/viewtopic.php?id=6372#pc52971">creature.ws</a><br />На подобии получилось следующее:<br /></p><div class="codebox"><pre><code>#SingleInstance Off
Gui, Show, w250 h0 ,Gui для наглядности
Process, priority, , Realtime
Pid1 := ErrorLevel

Loop
{
for Process in ComObjGet(&quot;winmgmts:&quot;).InstancesOf(&quot;Win32_Process&quot;)
if (InStr(Process.CommandLine,A_ScriptName) &amp;&amp; Process.ProcessId!=%Pid1%)
{
   ProcessId := Process.ProcessId
   SearchProcess := Process.CommandLine
      If ProcessId-Pid1=0
      {
         Goto ExitLoop
      }
      Else
      {
         OldPar := &quot;1&quot;
         RegExMatch(SearchProcess, A_ScriptName &quot;(.*)&quot;, OldPar)
         StringReplace,OldPar,OldPar,%A_ScriptName%,,All
         Process.Terminate
      }
}
}
ExitLoop:
If OldPar
MsgBox Скрипт перезапущен `n %OldPar%
Else
MsgBox Скрипт запущен в первые
Return

Escape::
GuiClose:
ExitApp</code></pre></div><p>Не понимаю как правильно написать,<br /></p><div class="codebox"><pre><code>if (InStr(Process.CommandLine,A_ScriptName) &amp;&amp; Process.ProcessId!=%Pid1% &amp;&amp; Process.Caption=AutoHotkey.exe)</code></pre></div><p>что-бы реагировало только на скрипты, вместо того, что есть:<br /></p><div class="codebox"><pre><code>if (InStr(Process.CommandLine,A_ScriptName) &amp;&amp; Process.ProcessId!=%Pid1%)</code></pre></div><p>которая закрывает всё содержащее имя скрипта(блокноты итп)</p>]]></content>
			<author>
				<name><![CDATA[Nikva]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27416</uri>
			</author>
			<updated>2015-11-06T08:30:25Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=98707#p98707</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: #SingleInstance Force как определить был ли запущен скрипт]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=98548#p98548" />
			<content type="html"><![CDATA[<p>Попытался сделать через посыл сообщения, но поток &quot;нового&quot; скрипта не стартует пока не завершится &quot;старый&quot;. Так что только через файл.</p><div class="codebox"><pre><code>#SingleInstance,Force
OnExit,EXIT

iniread,ExitReason,%A_scriptdir%\ExitReason,A_ExitReason,A_ExitReason
filedelete,%A_scriptdir%\ExitReason
tooltip,% ExitReason
return

f1::
return


exit:
IniWrite,%A_ExitReason%,%A_scriptdir%\ExitReason,A_ExitReason,A_ExitReason
exitapp



</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alectric]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26027</uri>
			</author>
			<updated>2015-10-30T12:31:32Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=98548#p98548</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: #SingleInstance Force как определить был ли запущен скрипт]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=98536#p98536" />
			<content type="html"><![CDATA[<p><a href="http://www.script-coding.com/AutoHotkey/OnExit.html">OnExit</a> с <a href="http://www.script-coding.com/AutoHotkey/Variables.1.0.46.07.html#A_ScriptName">A_ExitReason</a> рассматривал как вариант, но не хочеться создавать файлы при работе срипта.</p>]]></content>
			<author>
				<name><![CDATA[Nikva]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27416</uri>
			</author>
			<updated>2015-10-30T09:01:33Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=98536#p98536</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: #SingleInstance Force как определить был ли запущен скрипт]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=98532#p98532" />
			<content type="html"><![CDATA[<p>Возможно, можно мониторить сообщение закрытия (надо погуглить), и записывать в файл по OnExit, затем считывать на старте этот файл... возможно это бред.</p>]]></content>
			<author>
				<name><![CDATA[Alectric]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26027</uri>
			</author>
			<updated>2015-10-30T08:51:45Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=98532#p98532</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: #SingleInstance Force как определить был ли запущен скрипт]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=98529#p98529" />
			<content type="html"><![CDATA[<p>Есть ли способ узнать заменял ли новый процесс скрипта старый, при его запуске с директивой <strong>#SingleInstance Force</strong>, для не скомпилированного скрипта.<br />Код ниже работает только для скомпилированной версии, и я не уверен, что он будет всегда корректно срабатывать.</p><div class="codebox"><pre><code>#NoEnv
#Persistent
#NoTrayIcon
#SingleInstance Off
Gui, Show, w250 h0 ,Gui для наглядности

Process, priority, , Realtime
Pid := ErrorLevel

Process, Wait, test.exe, 0.1
If ErrorLevel != %Pid%
	{
	Process, Close, % ErrorLevel
	MsgBox Старый процесс закрыт как &quot;#SingleInstance Force&quot;
	}
Return

GuiClose:
ExitApp</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Nikva]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27416</uri>
			</author>
			<updated>2015-10-30T08:33:30Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=98529#p98529</id>
		</entry>
</feed>
