Ive have developed a Program That enables the user to Make a process of There choice load a "hello World" Dll, But the user has to Input the Processes PID.

I have two problems,

1. How do I Retrevive the process PID from process name?
2. My Program has the Hello World Dll in its resources, how would i make my Program 'Drop' The Dll at runtime?

Thanks in Advance

Here's one way to find the PID from the exe filename.

#include <windows.h>
#include <tlhelp32.h>
DWORD PID_from_EXE (char *exe_name)
{
    DWORD ret = 0;
    PROCESSENTRY32 pe32 = {sizeof (PROCESSENTRY32)};

    HANDLE hProcSnap = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
    if (hProcSnap == INVALID_HANDLE_VALUE) return 0;

    if (Process32First (hProcSnap, &pe32))
        do
            if (!strcmp (pe32.szExeFile, exe_name)) {
                ret = pe32.th32ProcessID;
                break;
            }
        while (Process32Next (hProcSnap, &pe32));

    CloseHandle (hProcSnap);
    return ret;
}

Look up "DLL injection" for your other question.

Here's one way to find the PID from the exe filename.

#include <windows.h>
#include <tlhelp32.h>
DWORD PID_from_EXE (char *exe_name)
{
    DWORD ret = 0;
    PROCESSENTRY32 pe32 = {sizeof (PROCESSENTRY32)};

    HANDLE hProcSnap = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
    if (hProcSnap == INVALID_HANDLE_VALUE) return 0;

    if (Process32First (hProcSnap, &pe32))
        do
            if (!strcmp (pe32.szExeFile, exe_name)) {
                ret = pe32.th32ProcessID;
                break;
            }
        while (Process32Next (hProcSnap, &pe32));

    CloseHandle (hProcSnap);
    return ret;
}

Look up "DLL injection" for your other question.

Thats what im doing

Thank you for this compact fuction which i was looking for

Here's one way to find the PID from the exe filename.

#include <windows.h>
#include <tlhelp32.h>
DWORD PID_from_EXE (char *exe_name)
{
    DWORD ret = 0;
    PROCESSENTRY32 pe32 = {sizeof (PROCESSENTRY32)};

    HANDLE hProcSnap = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
    if (hProcSnap == INVALID_HANDLE_VALUE) return 0;

    if (Process32First (hProcSnap, &pe32))
        do
            if (!strcmp (pe32.szExeFile, exe_name)) {
                ret = pe32.th32ProcessID;
                break;
            }
        while (Process32Next (hProcSnap, &pe32));

    CloseHandle (hProcSnap);
    return ret;
}

Look up "DLL injection" for your other question.

This article has been dead for over six months. Start a new discussion instead.