Click here to Skip to main content
12,401,324 members (39,624 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VC8.0 C++
How to check whether an exe is running or not??
Posted 27-Jul-11 1: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 27-Jul-11 7:27am
   
Thats great!!! My 5
SP 24 27-Jul-11 7:29am
   
:)
poth2 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 27 Jul 2011
Copyright © CodeProject, 1999-2016
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