Hello,
I run EnumProcesses(), to find if the progam "NurOper.exe" is running I debuged it and although "NurOper.exe" is running its don't return it,
its return all ather programs include my program- "nurman.exe" what can be the resone for it ,I must know if the progam "NurOper.exe" is running in order not to run it twice,
thank for advance .
the code is:
bool IsRunning=false;
int num=0;
DWORD aProcesses[1024], cbNeeded, cProcesses;
ULONG lCpuusage = 0;
UINT index;
double percent;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses),&cbNeeded ) )
return false;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
CString str;
for (int i = 0; i < cProcesses; i++ )
if( aProcesses[i] != 0 )
{
TCHAR szProcessName[MAX_PATH] = TEXT("");
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE,aProcesses[i] );
// Get the process name.
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod,sizeofhMod),&cbNeeded))
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName)/sizeof(TCHAR) );
}
}
str=(CString)szProcessName;
// Print the process name and identifier.
if(str.Compare(L"nurman.exe")==0 )
if(num==0)
num=1;
else if(num==1)
exit(1);
if(str.Compare(L"NurOper.exe")==0 )
IsRunning=true;
CloseHandle( hProcess );
}
if(!IsRunning)
_beginthread(runExe, 0, (void*)12 );
Comments
[link=http://support.microsoft.com/kb/243953]http://support.microsoft.com/kb/243953[/link]
[/color]