Тема: AHK: Как убить копии прцесса?
Необходимо что бы скрипт перехватывал копии заданного процесса и закрывал их, т.е. что бы процесс всегда был один и не клонировался.Помогите пожалуйста реализовать.
Вы не вошли. Пожалуйста, войдите или зарегистрируйтесь.
Страницы 1
Чтобы отправить ответ, вы должны войти или зарегистрироваться
Необходимо что бы скрипт перехватывал копии заданного процесса и закрывал их, т.е. что бы процесс всегда был один и не клонировался.Помогите пожалуйста реализовать.
А что за процесс? Случайно, не процесс скрипта?
Нет не скрипта.
А что за процесс — секрет?
Процесс игры. Sphere
Вот на примере Блокнота. Скрипт запускает Блокнот, убивает другие Блокноты, если присутствуют, и не позволяет им открываться. Когда запущенный Блокнот закрывается, скрипт завершает работу.
AdjustPrivileges()
Run, notepad.exe,,, PID ; здесь вместо notepad.exe указать путь к исполнимому файлу программы
Loop
{
; здесь вместо notepad.exe указать имя процесса, как оно отображается в Диспетчере задач
CloseDoubleProcess("notepad.exe", 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("OpenProcess", UInt, 0x0400, Int, false, UInt, ErrorLevel)
; Open an adjustable access token with this process (TOKEN_ADJUST_PRIVILEGES = 32)
DllCall("Advapi32.dll\OpenProcessToken", 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("Advapi32.dll\LookupPrivilegeValue" . (A_IsUnicode ? "W" : "A")
, UInt, 0, Str, "SeDebugPrivilege", "Int64P", luid)
NumPut(luid, ti, 4, "int64")
NumPut(2, ti, 12) ; enable this privilege: SE_PRIVILEGE_ENABLED = 2
; Update the privileges of this process with the new access token:
DllCall("Advapi32.dll\AdjustTokenPrivileges", UInt, t, Int, false
, UInt, &ti, UInt, 0
, UInt, 0, UInt, 0)
DllCall("CloseHandle", UInt, h) ; close this process handle to save memory
}
CloseDoubleProcess(name, PID)
{
s := 4096 ; size of buffers and arrays (4 KB)
hModule := DllCall("LoadLibrary", Str, "Psapi.dll") ; increase performance by preloading the libaray
s := VarSetCapacity(a, s) ; an array that receives the list of process identifiers:
DllCall("Psapi.dll\EnumProcesses", UInt, &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("OpenProcess", UInt, 0x0010 | 0x0400, Int, false, UInt, id)
VarSetCapacity(n, s, 0) ; a buffer that receives the base name of the module:
DllCall("Psapi.dll\GetModuleBaseName" . (A_IsUnicode ? "W" : "A")
, UInt, h, UInt, 0, Str, n, UInt, s)
DllCall("CloseHandle", UInt, h) ; close process handle to save memory
if (n = name && id != PID)
Process, Close, % id
}
DllCall("FreeLibrary", UInt, hModule) ; unload the library to free memory
}
Страницы 1
Чтобы отправить ответ, вы должны войти или зарегистрироваться