<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Как убить копии прцесса?]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=5510</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=5510&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Как убить копии прцесса?».]]></description>
		<lastBuildDate>Mon, 14 Feb 2011 10:40:44 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Как убить копии прцесса?]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=45139#p45139</link>
			<description><![CDATA[<p>Вот на примере Блокнота. Скрипт запускает Блокнот, убивает другие Блокноты, если присутствуют, и не позволяет им открываться. Когда запущенный Блокнот закрывается, скрипт завершает работу.<br /></p><div class="codebox"><pre><code>AdjustPrivileges()
Run, notepad.exe,,, PID   ; здесь вместо notepad.exe указать путь к исполнимому файлу программы
Loop
{
; здесь вместо notepad.exe указать имя процесса, как оно отображается в Диспетчере задач
   CloseDoubleProcess(&quot;notepad.exe&quot;, PID)
   
   Process, Exist, %PID%
   if !ErrorLevel
      ExitApp
      
   Sleep, 1000
}
      
AdjustPrivileges()
{
   Process, Exist  ; sets ErrorLevel to the PID of this running script
   ; Get the handle of this script with PROCESS_QUERY_INFORMATION (0x0400)
   h := DllCall(&quot;OpenProcess&quot;, UInt, 0x0400, Int, false, UInt, ErrorLevel)
   ; Open an adjustable access token with this process (TOKEN_ADJUST_PRIVILEGES = 32)
   DllCall(&quot;Advapi32.dll\OpenProcessToken&quot;, UInt, h, UInt, 32, UIntP, t)
   VarSetCapacity(ti, 16, 0)  ; structure of privileges
   NumPut(1, ti, 0)  ; one entry in the privileges array...
   ; Retrieves the locally unique identifier of the debug privilege:
   DllCall(&quot;Advapi32.dll\LookupPrivilegeValue&quot; . (A_IsUnicode ? &quot;W&quot; : &quot;A&quot;)
      , UInt, 0, Str, &quot;SeDebugPrivilege&quot;, &quot;Int64P&quot;, luid)
   NumPut(luid, ti, 4, &quot;int64&quot;)
   NumPut(2, ti, 12)  ; enable this privilege: SE_PRIVILEGE_ENABLED = 2
   ; Update the privileges of this process with the new access token:
   DllCall(&quot;Advapi32.dll\AdjustTokenPrivileges&quot;, UInt, t, Int, false
                                               , UInt, &amp;ti, UInt, 0
                                               , UInt, 0, UInt, 0)
   DllCall(&quot;CloseHandle&quot;, UInt, h)  ; close this process handle to save memory
}

CloseDoubleProcess(name, PID)
{
   s := 4096  ; size of buffers and arrays (4 KB)

   hModule := DllCall(&quot;LoadLibrary&quot;, Str, &quot;Psapi.dll&quot;)  ; increase performance by preloading the libaray
   s := VarSetCapacity(a, s)  ; an array that receives the list of process identifiers:
   DllCall(&quot;Psapi.dll\EnumProcesses&quot;, UInt, &amp;a, UInt, s, UIntP, r)
   Loop, % r // 4  ; parse array for identifiers as DWORDs (32 bits):
   {
      id := NumGet(a, A_Index * 4)
      ; Open process with: PROCESS_VM_READ (0x0010) | PROCESS_QUERY_INFORMATION (0x0400)
      h := DllCall(&quot;OpenProcess&quot;, UInt, 0x0010 | 0x0400, Int, false, UInt, id)

      VarSetCapacity(n, s, 0)  ; a buffer that receives the base name of the module:
      DllCall(&quot;Psapi.dll\GetModuleBaseName&quot; . (A_IsUnicode ? &quot;W&quot; : &quot;A&quot;)
         , UInt, h, UInt, 0, Str, n, UInt, s)

      DllCall(&quot;CloseHandle&quot;, UInt, h)  ; close process handle to save memory
      if (n = name &amp;&amp; id != PID)
         Process, Close, % id
   }
   DllCall(&quot;FreeLibrary&quot;, UInt, hModule)  ; unload the library to free memory
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Mon, 14 Feb 2011 10:40:44 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=45139#p45139</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как убить копии прцесса?]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=45123#p45123</link>
			<description><![CDATA[<p>Процесс игры. Sphere</p>]]></description>
			<author><![CDATA[null@example.com (metlick)]]></author>
			<pubDate>Sun, 13 Feb 2011 18:18:07 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=45123#p45123</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как убить копии прцесса?]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=45118#p45118</link>
			<description><![CDATA[<p>А что за процесс — секрет? <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 13 Feb 2011 17:42:27 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=45118#p45118</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как убить копии прцесса?]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=45106#p45106</link>
			<description><![CDATA[<p>Нет не скрипта.</p>]]></description>
			<author><![CDATA[null@example.com (metlick)]]></author>
			<pubDate>Sun, 13 Feb 2011 13:18:40 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=45106#p45106</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как убить копии прцесса?]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=45102#p45102</link>
			<description><![CDATA[<p>А что за процесс? Случайно, не процесс скрипта?</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Sun, 13 Feb 2011 09:19:24 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=45102#p45102</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Как убить копии прцесса?]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=45097#p45097</link>
			<description><![CDATA[<p>Необходимо что бы скрипт перехватывал копии заданного процесса и закрывал их, т.е. что бы процесс всегда был один и не клонировался.Помогите пожалуйста реализовать.</p>]]></description>
			<author><![CDATA[null@example.com (metlick)]]></author>
			<pubDate>Sun, 13 Feb 2011 08:53:36 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=45097#p45097</guid>
		</item>
	</channel>
</rss>
