<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Как убить копии прцесса?]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=5510&amp;type=atom" />
	<updated>2011-02-14T10:40:44Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=5510</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как убить копии прцесса?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=45139#p45139" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2011-02-14T10:40:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=45139#p45139</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как убить копии прцесса?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=45123#p45123" />
			<content type="html"><![CDATA[<p>Процесс игры. Sphere</p>]]></content>
			<author>
				<name><![CDATA[metlick]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26594</uri>
			</author>
			<updated>2011-02-13T18:18:07Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=45123#p45123</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как убить копии прцесса?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=45118#p45118" />
			<content type="html"><![CDATA[<p>А что за процесс — секрет? <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2011-02-13T17:42:27Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=45118#p45118</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как убить копии прцесса?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=45106#p45106" />
			<content type="html"><![CDATA[<p>Нет не скрипта.</p>]]></content>
			<author>
				<name><![CDATA[metlick]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26594</uri>
			</author>
			<updated>2011-02-13T13:18:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=45106#p45106</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Как убить копии прцесса?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=45102#p45102" />
			<content type="html"><![CDATA[<p>А что за процесс? Случайно, не процесс скрипта?</p>]]></content>
			<author>
				<name><![CDATA[YMP]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=81</uri>
			</author>
			<updated>2011-02-13T09:19:24Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=45102#p45102</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Как убить копии прцесса?]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=45097#p45097" />
			<content type="html"><![CDATA[<p>Необходимо что бы скрипт перехватывал копии заданного процесса и закрывал их, т.е. что бы процесс всегда был один и не клонировался.Помогите пожалуйста реализовать.</p>]]></content>
			<author>
				<name><![CDATA[metlick]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26594</uri>
			</author>
			<updated>2011-02-13T08:53:36Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=45097#p45097</id>
		</entry>
</feed>
