用 CreateProcess产生的进程,如何用程序方法杀掉.
CreateProcess(NULL,"c:notepad.exe",NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL, &stinfo,&procinfo);
WaitForSingleObject(procinfo.hProcess,5000);//等5秒钟,如果程序没有做完,就杀掉它
下面用什么语句来完成
CreateProcess(NULL,"c:notepad.exe",NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL, &stinfo,&procinfo);
WaitForSingleObject(procinfo.hProcess,5000);//等5秒钟,如果程序没有做完,就杀掉它
下面用什么语句来完成
解决方案 »
- 请教高手~~~给讲解一下这段程序每句代码的含义~~~多谢啦
- 关于优先级的问题
- 开发了一个全自动实时传真收发软件,现完全免费对外发布,欢迎大家批评指正!(含代码及完整使用说明),值此新年来临之际,特备薄礼,望大家笑纳!
- 关于COM的几个小问题,我觉得比较难理解,期待耐心的热心的人
- C++杂志开始征稿了!!!请大家踊跃投稿!
- 怎么向CListCtrl中加入图象?
- 在VC++用ADO,求连接远程ORACLE数据库的连接字符串?
- 怎样枚举窗体中的控件?
- 那个API函数能获取屏幕的分辨率
- 可变参数
- 请教一下显示位图的问题,为什么下面的代码不起作用?
- 请问如何用win API实现从文件中偏移量为m的位置读取n个字节
HANDLE hProcess, // handle to the process
UINT uExitCode // exit code for the process
);
if( pid > 0 )
{
HANDLE h = OpenProcess( PROCESS_ALL_ACCESS, TRUE, pid );
if( h != NULL )
{
TerminateProcess( h, 0 );
}
}
The ExitProcess function ends a process and all its threads. VOID ExitProcess(
UINT uExitCode // exit code for all threads
);
Parameters
uExitCode
Specifies the exit code for the process, and for all threads that are 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
This function does not return a value. Res
ExitProcess is the preferred method of ending a process. This function provides a clean process shutdown. This includes calling the entry-point function of all attached dynamic-link libraries (DLLs) with a value indicating that the process is detaching from the DLL. If a process terminates by calling TerminateProcess, the DLLs that the process is attached to are not notified of the process termination. After all attached DLLs have executed any process termination value, this function terminates the current process. Terminating a process causes the following: All of the object handles opened by the process are closed.
All of the threads in the process terminate their execution.
The state of the process object becomes signaled, satisfying any threads that had been waiting for the process to terminate.
The states of all threads of the process become signaled, satisfying any threads that had been waiting for the threads to terminate.
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 operating system. A process object is deleted when the last handle to the process is closed. The ExitProcess, ExitThread, CreateThread, CreateRemoteThread functions, and a process that is starting (as the result of a call by CreateProcess) are serialized between each other within a process. Only one of these events can happen in an address space at a time. This means the following restrictions hold: During process startup and DLL initialization routines, new threads can be created, but they do not begin execution until DLL initialization is done for the process.
Only one thread in a process can be in a DLL initialization or detach routine at a time.
ExitProcess does not return until no threads are in their DLL initialization or detach routines.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.See Also
Processes and Threads Overview, Process and Thread Functions, CreateProcess, CreateRemoteThread, CreateThread, ExitThread, GetExitCodeProcess, GetExitCodeThread, OpenProcess, TerminateProcess