Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Потрепаться";
Текущий архив: 2004.04.04;
Скачать: [xml.tar.bz2];

Вниз

Удаление процесса программнім путём   Найти похожие ветки 

 
Ivane   (2004-03-06 00:00) [0]

Пишу одну интересную программу... только, вот, проблема - такое уже написано. Если запустить мою программу и программу написанную проффессиональными программистами, то последняя просто перестаёт отвечать на запросы системы :-). Принял стратегическое решение - программно закрывать "конкурентов" при запуске. Прочитал кучу документации и нашёл  DestroyWindow. Написал. Не работает. Просто ничего не делает. HWnd нахожу правильно, т.к. CloseWindow работает прекрасно. ПОМОГИТЕ, ПОЖАЛУЙСТА!!!


 
Ihor Osov'yak ©   (2004-03-06 01:50) [1]

>Пишу одну интересную программу...
На здоровье.

>только, вот, проблема - такое уже написано.
А оно почти всегда так.

>Если запустить мою программу и программу написанную проффессиональными >программистами, то последняя просто перестаёт отвечать на запросы >системы :-).

сугубо имхо - очень вероятно, что у кого-то кривы руки.

>Принял стратегическое решение - программно закрывать "конкурентов" при запуске.
Идиотское решение. Снова имхо.

>Прочитал кучу документации и нашёл  DestroyWindow.
Плохо читали. DestroyWindow ничего общего с уничтожением (закрытием) чужого процесса не имеет.

>Написал.
Что?
>Не работает.
Кто?
>Просто ничего не делает.
Ну, эта..  
>HWnd нахожу правильно, т.к. CloseWindow работает прекрасно.
Все может быть...
>ПОМОГИТЕ, ПОЖАЛУЙСТА!!!

Хм.. А вопрос собственно где? На который ответить нужно?


 
Rouse_ ©   (2004-03-06 03:41) [2]

> [1] Ihor Osov"yak ©   (06.03.04 01:50)
Виден системный поход ;)))

По сабжу:
HWnd нахожу правильно, т.к. CloseWindow работает прекрасно. ПОМОГИТЕ, ПОЖАЛУЙСТА!!!
Масло съел и день прошел?...

то последняя просто перестаёт отвечать на запросы системы
Хуками баловались?

Пишу одну интересную программу
А вот это самый интересный пункт - что за программа?


 
Gero ©   (2004-03-06 08:17) [3]

Короче, все дело как всегда в 17 строке.


 
TUser ©   (2004-03-06 13:21) [4]

Либо Вы в хуках не передали сообщение дальше, либо с профессиональными программерами проблемы.


 
Klev   (2004-03-06 17:32) [5]

1.А собственно что делает твоя программа?(если не секрет)
2.Прежде чем повторно задавать вопрос надо поискать ответ на аналогичный вопрос в faq, форумах итп.

Klev   (04.03.04 16:34) [3]
The TerminateProcess function terminates the specified process and all of its threads.

BOOL TerminateProcess(

  HANDLE hProcess, // handle to the process
  UINT uExitCode  // exit code for the process  
 );

Parameters

hProcess

Identifies the process to terminate.
Windows NT: The handle must have PROCESS_TERMINATE access. For more information, see Process Objects.

uExitCode

Specifies the exit code for the process and for all threads terminated as a result of this call. Use the GetExitCodeProcess
function to retrieve the process"s exit value. Use the GetExitCodeThread function to retrieve a thread"s exit value.

Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The TerminateProcess function is used to unconditionally cause a process to exit. Use it only in extreme circumstances. The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess.
TerminateProcess causes all threads within a process to terminate, and causes a process to exit, but DLLs attached to the process are not notified that the process is terminating.

Terminating a process causes the following:

1. All of the object handles opened by the process are closed.
2. All of the threads in the process terminate their execution.
3. The state of the process object becomes signaled, satisfying any threads that had been waiting for the process to terminate.
4. The states of all threads of the process become signaled, satisfying any threads that had been waiting for the threads to terminate.
5. The termination status of the process changes from STILL_ACTIVE to the exit value of the process.

Terminating a process does not cause child processes to be terminated.
Terminating a process does not necessarily remove the process object from the system. A process object is deleted when the last handle to the process is closed.

See Also

ExitProcess, OpenProcess, GetExitCodeProcess, GetExitCodeThread

Ну а для того, что бы узнать hprocess(сначала processid):

The GetWindowThreadProcessId function retrieves the identifier of the thread that created the specified window and, optionally, the identifier of the process that created the window. This function supersedes the GetWindowTask function.

DWORD GetWindowThreadProcessId(

  HWND hWnd, // handle of window
  LPDWORD lpdwProcessId  // address of variable for process identifier
 );

Parameters

hWnd

Identifies the window.

lpdwProcessId

Points to a 32-bit value that receives the process identifier. If this parameter is not NULL, GetWindowThreadProcessId copies the identifier of the process to the 32-bit value; otherwise, it does not.

Return Values

The return value is the identifier of the thread that created the window.

и полученный processid передать в качестве пареметра следующей функции:

The OpenProcess function returns a handle of an existing process object.

HANDLE OpenProcess(

  DWORD dwDesiredAccess, // access flag
  BOOL bInheritHandle, // handle inheritance flag
  DWORD dwProcessId  // process identifier
 );

Parameters

dwDesiredAccess

Specifies the access to the process object. For operating systems that support security checking, this access is checked against any security descriptor for the target process. Any combination of the following access flags can be specified in addition to the STANDARD_RIGHTS_REQUIRED access flags:

Access Description
PROCESS_ALL_ACCESS Specifies all possible access flags for the process object.
PROCESS_CREATE_PROCESS Used internally.
PROCESS_CREATE_THREAD Enables using the process handle in the CreateRemoteThread function to create a thread in the process.
PROCESS_DUP_HANDLE Enables using the process handle as either the source or target process in the DuplicateHandle function to duplicate a handle.
PROCESS_QUERY_INFORMATION Enables using the process handle in the GetExitCodeProcess and GetPriorityClass functions to read information from the process object.
PROCESS_SET_INFORMATION Enables using the process handle in the SetPriorityClass function to set the priority class of the process.
PROCESS_TERMINATE Enables using the process handle in the TerminateProcess function to terminate the process.
PROCESS_VM_OPERATION Enables using the process handle in the VirtualProtectEx and WriteProcessMemory functions to modify the virtual memory of the process.
PROCESS_VM_READ Enables using the process handle in the ReadProcessMemory function to read from the virtual memory of the process.
PROCESS_VM_WRITE Enables using the process handle in the WriteProcessMemory function to write to the virtual memory of the process.
SYNCHRONIZE Windows NT only: Enables using the process handle in any of the wait functions to wait for the process to terminate.

bInheritHandle

Specifies whether the returned handle can be inherited by a new process created by the current process. If TRUE, the handle is inheritable.

dwProcessId

Specifies the process identifier of the process to open.

Return Values

If the function succeeds, the return value is an open handle of the specified process.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

The handle returned by the OpenProcess function can be used in any function that requires a handle to a process, such as the wait functions, provided the appropriate access rights were requested.
When you are finished with the handle, be sure to close it using the CloseHandle function.

примерчик:
procedure terminate; :)
var hprocess,procid:dword;
begin
GetWindowThreadProcessId(findwindow(nil,pchar("Kill_me!)),procid);

hProcess:=OpenProcess(PROCESS_CREATE_THREAD or PROCESS_VM_WRITE or process_terminate or
PROCESS_VM_OPERATION, FALSE, procid);

terminateprocess(hprocess,0);

closehandle(hprocess);
end;

Ну вот собственно и все.


 
Petr V. Abramov ©   (2004-03-06 19:07) [6]

> Удаление процесса программнім путём
 процессы лучше удалять аппаратным путем :)


 
Gero ©   (2004-03-06 19:22) [7]

> процессы лучше удалять аппаратным путем :)

Молотком :)


 
Ivane ©   (2004-03-06 22:46) [8]

Спасибо всем, кто откликнулся :-)
А пишу я что-то наподобии WinAmp`a.


 
Nous Mellon ©   (2004-03-06 22:53) [9]

А так ты Винамп при загрузке вешаешь? Серьезное достижение, прими мои поздравления.



Страницы: 1 вся ветка

Форум: "Потрепаться";
Текущий архив: 2004.04.04;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.49 MB
Время: 0.092 c
1-1079615774
Serg Guk
2004-03-18 16:16
2004.04.04
Как определить имеет ли Юзер права администратора?


1-1079693529
АМБ
2004-03-19 13:52
2004.04.04
Скомпилированный файл имеет малые размеры


3-1078220239
Janbolat
2004-03-02 12:37
2004.04.04
Что такое loocup-поля


14-1078610351
Soft
2004-03-07 00:59
2004.04.04
Как настроить роутинг NetBios?


7-1074608063
MAXHO
2004-01-20 17:14
2004.04.04
LPT-порт и прерывания





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский