<?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=5385&amp;type=atom" />
	<updated>2011-01-15T17:59:35Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=5385</id>
		<entry>
			<title type="html"><![CDATA[AHK: Принудительное завершение, смена приоритетов процессов]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=43809#p43809" />
			<content type="html"><![CDATA[<p>Немного изменённый <a href="http://www.autohotkey.com/forum/topic649.html&amp;highlight=instant+process+priority+alteration">Instant process priority alteration</a>.<br /><em>Ctrl + Q</em> — меню,<br /><em>Ctrl + Esc</em> — принудительное завершение процесса.<br />Можно ли изменить такое поведение: после «зависания» некоторых приложений, попытка их завершения влечёт за собой также и выгрузку процесса Проводника?</p><div class="codebox"><pre><code>#SingleInstance Force
Menu, priority, add, Realtime, Change_P_Priority
Menu, priority, add, High, Change_P_Priority
Menu, priority, add, Above Normal, Change_P_Priority
Menu, priority, add, Normal, Change_P_Priority
Menu, priority, add, Below Normal, Change_P_Priority
Menu, priority, add, Low, Change_P_Priority
Menu, priority, add       
Menu, priority, add, Kill Process %a_tab%Ctrl+Esc, Kill_Process

^q::
IfEqual, 1,, WinGet, PID_Target, PID, A 
Else SetEnv, PID_Target, %1% 
Menu, priority, show        

Exit 
Return

Change_P_Priority:
  StringLeft, new_priority, A_ThisMenuItem, 1
  Process, Priority, %PID_Target%, %new_priority%
Return

^Esc::
Kill_Process:
  Gosub, Get_ExePath

  MsgBox, 4, Подтверждение, `n`tПроцесс:`t%Exe_Path%`t`t`n`tИД:`t%PID_Target%`n`n`tВыгрузить?`t`n`n
  IfMsgBox, Yes
    {
      If Exe_Path contains explorer.exe
      {
        ; Завершение процесса explorer.exe (без перезапуска Проводника)
        Process, Exist, Explorer.exe
        PID_Target := ErrorLevel 
        h_process := DllCall(&quot;OpenProcess&quot;, UInt, 0x1, Int, 0, UInt, PID_Target)   ; 0x1 — право доступа «PROCESS_TERMINATE»
        DllCall(&quot;TerminateProcess&quot;, UInt, h_process, UInt, 1) 
        DllCall(&quot;CloseHandle&quot;, UInt, h_process)
      }
      Else
        Process, Close, %PID_Target%
    }
  IfMsgBox, No
  Return
Return

Get_ExePath:
  ID_Wnd := WinExist( &quot;A&quot; ) ; получаем ID ОКНА
  If Not ID_Wnd ; если ОКНО не найдено...
  {
    MsgBox, Окно не найдено!
    Return ; конец скрипта
  }
  WinGet, PID_Target, PID, ahk_id %ID_Wnd% ; получаем PID найденного окна ОКНА
  Exe_Path := GetModuleFileNameEx( PID_Target ) ; вызываем функцию получения пути процесса ОКНА
  If Not Exe_Path ; если что-то не так...
  {
    MsgBox, Процесс не существует, или к нему нет доступа
    Return ; конец скрипта
  }
Return

GetModuleFileNameEx(PID) { ; shimanov - www.autohotkey.com/forum/viewtopic.php?p=54838#54838
hpr := DllCall( &quot;OpenProcess&quot;, UInt,1040, Int,0, UInt,PID )
If ( ErrorLevel or !hpr )
    Return
VarSetCapacity( Name,255 )
DllCall( &quot;psapi.dll\GetModuleFileNameExA&quot;, UInt,hPr, UInt,0, Str,Name, UInt,255 )
DllCall( &quot;CloseHandle&quot;, hPr )
Return, Name
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[DD]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=25263</uri>
			</author>
			<updated>2011-01-15T17:59:35Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=43809#p43809</id>
		</entry>
</feed>
