.EXE test
If you have Win2k or XP (if not then get it!) then you can use the task manager to show all processes. VC++ also comes with a utility program that shows processes too
Oops, should have clarified more. What I mean is that I want to test to see if a particular application is running from within my program. I want to know if there is a function that will return true/false or whatever, given a particular *.exe file. I''m using Visual C++ 6.0.
Certainly. Use the toolhelp API for Win95+ and NT5+:
CreateToolhelp32Snapshot
Process32First
Process32Next
or PSAPI for NT4+:
EnumProcesses
Edit: forgot about NT4!
[edited by - IndirectX on April 29, 2002 5:00:32 PM]
CreateToolhelp32Snapshot
Process32First
Process32Next
or PSAPI for NT4+:
EnumProcesses
Edit: forgot about NT4!
[edited by - IndirectX on April 29, 2002 5:00:32 PM]
Thanks IndirectX, that helped a lot. I now have a great little function to test if programs are running. In case anybody else ever needs something like this, I''ll post it here:
/////////////////////// bool IsAppRunning( char *filename ) - tests to see if the given filename is currently// running/////////////////////bool IsAppRunning( char *filenameIn, bool bReturnMessage ){ char szTemp[64]; HANDLE processes = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); PROCESSENTRY32 processEntry; processEntry.dwSize = sizeof(PROCESSENTRY32); Process32First( processes, &processEntry); while( GetLastError()!=ERROR_NO_MORE_FILES ) { //extract filename from path char *filename = PathFindFileName(processEntry.szExeFile); if( strcmp( _strlwr(filename), _strlwr( filenameIn ) ) == 0) { if(bReturnMessage) { sprintf(&szTemp[0], "%s is currently running", _strlwr( filenameIn ) ); MessageBox(NULL, szTemp, "Process Found", MB_OK); } return true; } Process32Next( processes, &processEntry); } CloseHandle(processes); if(bReturnMessage) { sprintf(&szTemp[0], "%s is not running.", _strlwr( filenameIn ) ); MessageBox(NULL, szTemp, "Process Not Found", MB_OK); } return false;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement