问题描述
我使用 CreateProcess()
创建了一个进程。这是代码:
I have created a process using CreateProcess()
. This is the code:
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
result = CreateProcess("C:\\AP\\DatabaseBase\\dbntsrv.exe", NULL, NULL, NULL, FALSE, 0, NULL, "C:\\ADP\\SQLBase", &si, &pi)
和processId的这个特定的进程?最后使用它来关闭此过程?
谢谢。
How can I get the Handle and processId of this specific process? And eventually use it to close this process?
Thank You.
推荐答案
$ c> pi 你得到:
In the struct pi
you get:
typedef struct _PROCESS_INFORMATION {
HANDLE hProcess;
HANDLE hThread;
DWORD dwProcessId;
DWORD dwThreadId;
} PROCESS_INFORMATION, *LPPROCESS_INFORMATION;
第一个参数是进程的句柄。
The first parameter is the handle to the process.
您可以使用该句柄结束过程:
You can use that handle to end the process:
BOOL WINAPI TerminateProcess(
__in HANDLE hProcess,
__in UINT uExitCode
);
句柄必须具有PROCESS_TERMINATE访问权限。有关详细信息,请参阅进程安全性和访问权限。
The handle must have the PROCESS_TERMINATE access right. For more information, see Process Security and Access Rights.
uExitCode [in]
要使用的退出代码由进程和线程终止作为此调用的结果。使用GetExitCodeProcess函数来检索进程的退出值。使用GetExitCodeThread函数来检索线程的退出值。
uExitCode [in]
The exit code to be used by the process and threads terminated as a result of this call. Use the GetExitCodeProcess function to retrieve a process's exit value. Use the GetExitCodeThread function to retrieve a thread's exit value.
这篇关于如何终止由CreateProcess()创建的进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!