yes i am using vista
thanks anyway for the explanation.
I have tried the following code under vista and it's working..Just want to share it for the benefit of otherss:
Code:
#include "stdafx.h"
#include <Psapi.h>
#include <atlbase.h>
#include <iostream>
#include <cstdlib>
#include "main.h"
#include <windows.h>
#include <tchar.h>
#define PROC_NAME "process name you are looking for"
void main( )
{
while(true){
WCHAR name[20];
ctow(name,PROC_NAME);
unsigned long gwID = GetTargetProcessIdFromProcname(name);
if (gwID >0){
//printf("found %s, pid: %d",PROC_NAME, gwID);
}
else{
printf("not found");
//std::system("Gadget_Server_V1.27.333.exe");
Sleep(10000);
}
}
}
unsigned long GetTargetProcessIdFromProcname(WCHAR *procName)
{
PROCESSENTRY32 pe = {0};
HANDLE thSnapshot = {0};
BOOL retval = false;
// Try to create a toolhelp snapshot and verify that it was actually created
thSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(thSnapshot == INVALID_HANDLE_VALUE)
{
printf("error");
return 0;
}
// Need to have this set for the WinAPI structures
pe.dwSize = sizeof(PROCESSENTRY32);
// Try to get the first process
retval = Process32First(thSnapshot, &pe);
// While we have processes to go through
while(retval)
{
char buff[100];
wtoc(buff,pe.szExeFile);
//strcpy(buff, pe.szExeFile);
//printf("exe: %s PID: %d\n",buff, pe.th32ProcessID);
// As soon as we find the process id, return it
if(StrStrI(procName,pe.szExeFile))
{
return pe.th32ProcessID;
}
// Otherwise, get try to get the next process
retval = Process32Next(thSnapshot,&pe);
}
// If we get here, no process ID was found, so return no
// process ID instead of the last process found.
return 0;
}