Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC8.0
How to check whether an exe is running or not??
Posted 27-Jul-11 2:01am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

BOOL CBaseOperation::IsExeRunning(CString strExe)
{
	HANDLE hProcessSnap;
	BOOL bRet = FALSE;
	CString csProcessList = _T("");
	DWORD dwID = 0;
	PROCESSENTRY32 pe32;
	// Take a snapshot of all processes in the system
	hProcessSnap=CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS,0);
	if(hProcessSnap == INVALID_HANDLE_VALUE)
	{
		bRet = FALSE;
		return bRet;
	}
	// Set the size of the structure before using it.
	pe32.dwSize =sizeof(PROCESSENTRY32);
	// Retrieve information about the first process,
	// and exit if unsuccessful
	if(!Process32First (hProcessSnap,&pe32))
	{
		CloseHandle( hProcessSnap );
		bRet = FALSE;
		return bRet;
	}
	// Now walk the snapshot of processes, and
	// display information about each process in turn
	while( Process32Next( hProcessSnap, &pe32 ))
	{
		if(strExe.Compare(pe32.szExeFile)==0)
		{
			return TRUE;
		}
	}
	CloseHandle( hProcessSnap );
	return bRet;
}
 
  Permalink  
Comments
Gokulnath007 at 27-Jul-11 7:27am
   
Thats great!!! My 5
SP 24 at 27-Jul-11 7:29am
   
:)
poth2 at 28-Jul-11 2:26am
   
I think it is necessary to compare strExe with the first process, too. Something like this:
 
if(!Process32First (hProcessSnap,&pe32))
{
CloseHandle( hProcessSnap );
bRet = FALSE;
return bRet;
}
// Now walk the snapshot of processes, and
// display information about each process in turn
do
{
if(strExe.Compare(pe32.szExeFile)==0)
{
return TRUE;
}
}while( Process32Next( hProcessSnap, &pe32 ));
CloseHandle( hProcessSnap );
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

bool isRunning = Process.GetProcessesByName("test").FirstOrDefault(p => p.MainModule.FileName.StartsWith(@"c:\loc1")) != default(Process);
  Permalink  
Comments
Gokulnath007 at 27-Jul-11 7:13am
   
What is Process here???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 285
1 DamithSL 265
2 CPallini 195
3 Maciej Los 175
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 27 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100