<?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=12602</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=12602&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Завершить поток в процессе».]]></description>
		<lastBuildDate>Mon, 10 Apr 2017 21:12:46 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Завершить поток в процессе]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=114987#p114987</link>
			<description><![CDATA[<p>Решил проблему. Проблема была в том что поток открывался только с правами на чтение. Заменил с правами на завершение потока и все заработало.</p><div class="codebox"><pre><code>TerminateThread(ThreadID)
{
    if !(hThread := DllCall(&quot;OpenThread&quot;, &quot;uint&quot;, 0x0001, &quot;int&quot;, 0, &quot;uint&quot;, ThreadID, &quot;ptr&quot;))
        return &quot;Error in OpenThread&quot;

    if (DllCall(&quot;TerminateThread&quot;,&quot;Ptr&quot;,hThread,&quot;UInt&quot;,0) = -1)
        return &quot;Error in TerminateThread&quot;, DllCall(&quot;CloseHandle&quot;, &quot;ptr&quot;, hThread)
    return true, DllCall(&quot;CloseHandle&quot;, &quot;ptr&quot;, hThread)
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Dworkin)]]></author>
			<pubDate>Mon, 10 Apr 2017 21:12:46 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=114987#p114987</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Завершить поток в процессе]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=114797#p114797</link>
			<description><![CDATA[<p>Так поток завершается функцией ExitThread.</p>]]></description>
			<author><![CDATA[null@example.com (svoboden)]]></author>
			<pubDate>Fri, 07 Apr 2017 23:39:28 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=114797#p114797</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Завершить поток в процессе]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=114793#p114793</link>
			<description><![CDATA[<p><strong>svoboden</strong>, спасибо за ответ, но мне надо убить принудительно поток в процессе, а не остановить его. В процессе много потоков у которых есть свой ид.</p><p>Дело в том что я использую одну длл библиотеку, которая подгружается таким образом:<br /></p><div class="codebox"><pre><code>
PATH_API := PathCombine(A_ScriptDir, &quot;Open-API.dll&quot;)

hModule := DllCall(&quot;LoadLibrary&quot;, Str, PATH_API)

PathCombine(abs, rel) {
    VarSetCapacity(dest, (A_IsUnicode ? 2 : 1) * 260, 1) ; MAX_PATH
    DllCall(&quot;Shlwapi.dll\PathCombine&quot;, &quot;UInt&quot;, &amp;dest, &quot;UInt&quot;, &amp;abs, &quot;UInt&quot;, &amp;rel)
    Return, dest
}</code></pre></div><p>но библиотека подгружается в процесс и видна в модулях, я не знаю как ее выгрузить из памяти. FreeLibrary не помогает.<br />Я тогда нашел такое решение: заморозить процесс, с помощью одной программы убить поток связаный с библиотекой, во второй программе принудительно выгрузить модуль из памяти. А хотелось бы это автоматизировать.</p>]]></description>
			<author><![CDATA[null@example.com (Dworkin)]]></author>
			<pubDate>Fri, 07 Apr 2017 22:04:59 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=114793#p114793</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Завершить поток в процессе]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=114790#p114790</link>
			<description><![CDATA[<p>ID может измениться, если это этот пример, то все работает:<br /></p><div class="codebox"><pre><code>Unicode          := A_IsUnicode ? &quot;W&quot; : &quot;&quot;

TH32CS_SNAPPROCESS := 0x00000002
TH32CS_SNAPTHREAD  := 0x00000004 
CreateToolhelp32Snapshot(Flags, th32ProcessID)
{
   return DllCall(&quot;CreateToolhelp32Snapshot&quot;, &quot;int&quot;, Flags, &quot;int&quot;, th32ProcessID)
}
 
Process32First(hSnapshot, pe)
{
   global Unicode
   return DllCall(&quot;Process32First&quot; . Unicode, &quot;int&quot;, hSnapshot, &quot;int&quot;, pe)
}
 
Process32Next(hSnapshot, pe)
{
   global Unicode
   return DllCall(&quot;Process32Next&quot; . Unicode, &quot;int&quot;, hSnapshot, &quot;int&quot;, pe)
}
 
Thread32First(hSnapshot, te)
{
   return DllCall(&quot;Thread32First&quot;, &quot;int&quot;, hSnapshot, &quot;int&quot;, te)
}
 
Thread32Next(hSnapshot, te)
{
   return DllCall(&quot;Thread32Next&quot;, &quot;int&quot;, hSnapshot, &quot;int&quot;, te)
}
 
THREAD_SUSPEND_RESUME := 0x0002
OpenThread(DesiredAccess, InheritHandle, ThreadId)
{
   return DllCall(&quot;OpenThread&quot; , &quot;int&quot;, DesiredAccess, &quot;int&quot;, InheritHandle, &quot;int&quot;, ThreadId)
}
 
SuspendThread(hThread)
{
   return DllCall(&quot;SuspendThread&quot;, &quot;int&quot;, hThread)
}
 
ResumeThread(hThread)
{
   return DllCall(&quot;ResumeThread&quot;, &quot;int&quot;, hThread)
}
 
CloseHandle(Handle)
{
   return DllCall(&quot;CloseHandle&quot;, &quot;int&quot;, Handle)
}
 
Gui Add, Button, x10 y5 w75 gL_Update, Обновить
Gui Add, Button, x100 y5 w75 gL_Stop, Stop
Gui Add, Button, x200 y5 w75 gL_Start, Start
Gui Add, ListView, x10 y35 r20 w450 -Multi, PID|имя процесса|статус
LV_ModifyCol(1, 50)
LV_ModifyCol(2, 300)
LV_ModifyCol(3, 50)
Update()
Gui Show
return
 
L_Update:
   Update()
return
 
L_Stop:
   Stop()
return
 
L_Start:
   Start()
return
 
Start()
{
   global TH32CS_SNAPTHREAD, THREAD_SUSPEND_RESUME
   row := LV_GetNext(0, &quot;Focused&quot;)
   LV_GetText(id, row)
   hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, id)
   VarSetCapacity(te, 28)
   NumPut(28, te, 0)
   str := &quot;&quot;
   test := Thread32First(hSnapshot, &amp;te)
   while test
   {
      if (id=NumGet(te, 12))
      {
         hThread := OpenThread(THREAD_SUSPEND_RESUME, 0, NumGet(te, 8))
         if (hThread=0)
         {
            LV_Modify(row, &quot;Col3&quot; , &quot;-1 (&quot; . a_lasterror . &quot;)&quot;)
            CloseHandle(hSnapshot)
            return
         }
         ret := ResumeThread(hThread)
         CloseHandle(hThread)
      }
      test := Thread32Next(hSnapshot, &amp;te)
   }
   CloseHandle(hSnapshot)
   LV_Modify(row, &quot;Col3&quot; , ret=0 ? 0 : ret-1)
}
 
Stop()
{
   global TH32CS_SNAPTHREAD, THREAD_SUSPEND_RESUME
   row := LV_GetNext(0, &quot;Focused&quot;)
   LV_GetText(id, row)
   hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, id)
   VarSetCapacity(te, 28)
   NumPut(28, te, 0)
   test := Thread32First(hSnapshot, &amp;te)
   while test
   {
      if (id=NumGet(te, 12))
      {
         hThread := OpenThread(THREAD_SUSPEND_RESUME, 0, NumGet(te, 8))
         if (hThread=0)
         {
            LV_Modify(row, &quot;Col3&quot; , &quot;-1 (&quot; . a_lasterror . &quot;)&quot;)
            CloseHandle(hSnapshot)
               return
         }
         ret := SuspendThread(hThread)
         CloseHandle(hThread)
      }
      test := Thread32Next(hSnapshot, &amp;te)
   }
   CloseHandle(hSnapshot)
   LV_Modify(row, &quot;Col3&quot; , ret+1)
}
 
Update()
{
   global TH32CS_SNAPPROCESS
   LV_Delete()
   hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
   pesize := A_IsUnicode ? 556 : 296
   VarSetCapacity(pe, pesize)
   NumPut(pesize, pe, 0)
   test := Process32First(hSnapshot, &amp;pe)
   while test
   {
      LV_Add(&quot;&quot;, NumGet(pe,8), StrGet(&amp;pe+36),&quot;?&quot;)
      test := Process32Next(hSnapshot, &amp;pe)
   }
   CloseHandle(hSnapshot)
}
 
GuiClose:
   ExitApp
return</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (svoboden)]]></author>
			<pubDate>Fri, 07 Apr 2017 21:35:51 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=114790#p114790</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Завершить поток в процессе]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=114785#p114785</link>
			<description><![CDATA[<p>Доброй ночи. Помогите пожалуйста.<br />Вот нашел код для замораживания потока по его иду:<br /></p><div class="codebox"><pre><code>SuspendThread(ThreadID)
{
    if !(hThread := DllCall(&quot;OpenThread&quot;, &quot;uint&quot;, 0x0002, &quot;int&quot;, 0, &quot;uint&quot;, ThreadID, &quot;ptr&quot;))
        return &quot;Error in OpenThread&quot;
    if (DllCall(&quot;SuspendThread&quot;, &quot;ptr&quot;, hThread) = -1)
        return &quot;Error in SuspendThread&quot;, DllCall(&quot;CloseHandle&quot;, &quot;ptr&quot;, hThread)
    return true, DllCall(&quot;CloseHandle&quot;, &quot;ptr&quot;, hThread)
}</code></pre></div><p>Что бы завершить его такой код не работает:<br /></p><div class="codebox"><pre><code>TerminateThread(ThreadID)
{
    if !(hThread := DllCall(&quot;OpenThread&quot;, &quot;uint&quot;, 0x0002, &quot;int&quot;, 0, &quot;uint&quot;, ThreadID, &quot;ptr&quot;))
        return &quot;Error in OpenThread&quot;

    if (DllCall(&quot;TerminateThread&quot;,&quot;Ptr&quot;,hThread,&quot;UInt&quot;,0) = -1)
        return &quot;Error in TerminateThread&quot;, DllCall(&quot;CloseHandle&quot;, &quot;ptr&quot;, hThread)
    return true, DllCall(&quot;CloseHandle&quot;, &quot;ptr&quot;, hThread)
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Dworkin)]]></author>
			<pubDate>Fri, 07 Apr 2017 20:25:38 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=114785#p114785</guid>
		</item>
	</channel>
</rss>
