获取进程pid,ppid以及进程名

获取pid:

pid = GetCurrentProcessId();

获取ppid和进程名:

BOOL GetProcessInfoWithPID(DWORD pid, DWORD* ppid, WCHAR* process_name)
{
	BOOL			result = FALSE;
	HANDLE			snapshot_handle = NULL;
	PROCESSENTRY32W	process_entry32;
	BOOL			process_return = FALSE;

	do
	{
		snapshot_handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
		if (snapshot_handle == INVALID_HANDLE_VALUE)
		{
			break;
		}
		process_entry32.dwSize = sizeof(process_entry32);
		process_return = Process32FirstW(snapshot_handle, &process_entry32);

		while (process_return)
		{
			if (process_entry32.th32ProcessID == pid)
			{
				if (ppid != NULL)
				{
					*ppid = process_entry32.th32ParentProcessID;
				}
				if (process_name != NULL)
				{
					lstrcpyW(process_name, process_entry32.szExeFile);
				}
				result = TRUE;
				break;
			}
			process_entry32.dwSize = sizeof(process_entry32);
			process_return = Process32NextW(snapshot_handle, &process_entry32);
		}

	} while (0);

	if (snapshot_handle)
	{
		CloseHandle(snapshot_handle);
	}
	return result;
}

该函数的第二个或第三个参数如不需要可以填零。