Thread: Detect Running Programs?

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    3

    Question Detect Running Programs?

    Does anyone have any idea to detect if the EXE files is still running or not?

    I try to make a little anti-virus removal. The program can scan and detect the virus then try to terminate the process & delete it...

    Can anybody give me any idea...

  2. #2
    Disrupting the universe Mad_guy's Avatar
    Join Date
    Jun 2005
    Posts
    258
    Here's a function I wrote for a tiny debugger I made a while back that gives some rudimentary info on processes (the whole script can be found here):

    Code:
    void process_snap(void) {
    	FILE *hFile;
    	HANDLE hSnapshot;
    	PROCESSENTRY32 ppe32E = { sizeof(PROCESSENTRY32) };
    	int proccount = 0;
    
    	if(NULL == (hFile = fopen("proc_snap.log","a"))) {
    		printf("+--Could not open log file--+\n");
    		goto end;
    	}
    
    
    	hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    	if(NULL == hSnapshot) {
    		fprintf(hFile,"+--Could not create process snapshot: %d--+\n",GetLastError());
    		goto end;
    	}
    
    
    
    	if(FALSE == Process32First(hSnapshot,&ppe32E)) {
    		fprintf(hFile,"+--Could not get first process: %d--+\n",GetLastError());
    		goto end;
    	}
    	fprintf(hFile,"+---PROCESS SNAP RESULTS:-----+\n");
    
    	do {
    		fprintf(hFile,"Process   %d:\n",++proccount);
    		fprintf(hFile,"--Path:   %s\n",ppe32E.szExeFile);
    		fprintf(hFile,"--ProcID: 0x%x\n",ppe32E.th32ProcessID);
    	} while(FALSE != Process32Next(hSnapshot,&ppe32E));
    
    	fprintf(hFile,"+-----------------------------+\n");
    	fprintf(hFile,"\n\n\n");
    	printf("+--Everything snapped, logs in proc_snap.log--+\n");
    
    
    	end:
    		fclose(hFile);
    }

    You can of course do it other ways, namely using things like the native API, but I feel that's beyond the basic scope of what you're asking (at least right now.)
    operating systems: mac os 10.6, debian 5.0, windows 7
    editor: back to emacs because it's more awesomer!!
    version control: git

    website: http://0xff.ath.cx/~as/

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    3
    Thanks alot man... The code giving me some idea how to retrieve an information from the running process...

    I currently trying to make a function that can force to terminate & delete an EXE files that currently running...

    Lets say,
    ABC.EXE is currently running...
    Then I want to force delete this files...

    Did anybody have an idea? Or Pseudo Code...

    thanks again for Mad_guy... Just what i need...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with running programs with c++
    By mendel69 in forum C++ Programming
    Replies: 5
    Last Post: 10-12-2006, 07:50 AM
  2. Replies: 2
    Last Post: 05-12-2006, 10:28 AM
  3. executing c++ programs on the web
    By gulti01 in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2002, 03:12 AM
  4. Running programs as Services
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 10-20-2001, 04:17 AM