Hi
If it is a console window from Windows use:
Code:
DWORD h1 = GetCurrentProcessId();
HANDLE h2 = OpenProcess(PROCESS_ALL_ACCESS, 0, h1);
-----
the code abowe is to retrive your process handle
Use the following code to retrive all the ID from the system
but it works only with Win2k and you will need PSAPI.DLL
Code:
HMODULE hPsapi = LoadLibrary("PSAPI.DLL");
if (hPsapi == NULL) return 1;
typedef BOOL (__stdcall * EnumProc)(DWORD*,DWORD,DWORD*);
EnumProc enumProcessesStub = NULL;
enumProcessesStub = (EnumProc)GetProcAddress(hPsapi,"EnumProcesses");
if (!enumProcessesStub) return 1;
DWORD needed = 0;
DWORD* dwArray = new DWORD[2000];
enumProcessesStub(dwArray ,0,&needed);
if (enumProcessesStub(dwArray,2000*sizeof(DWORD),&needed))
{
printf("%d ids retrived\n", needed);
}
// free memory
delete dwArray;
// free psapi.dll
FreeLibrary(hPsapi);