Terminate Process by Specific FullFilePath

This is a discussion on Terminate Process by Specific FullFilePath within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I already make a terminating processes code. But I want to use it to terminate any running process by ...

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

    Question Terminate Process by Specific FullFilePath

    Hello,

    I already make a terminating processes code. But I want to use it to terminate any running process by specifiying a file path. For example:

    stopproc ( "C:\\Windows\\blablabla\\testing\\testing.exe" );

    I'm currently can make it to stop process by a specific name and not a specific full path name. Can anyone help me to solve this problem. I really appreciate it if anyone could help.

    Here it is my sample code:
    Code:
    void stopproc(char * process_name)
    {
    	register BOOL term;
    	lSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    	uProcess.dwSize = sizeof(uProcess);
    	rProcessFound = Process32First(lSnapshot,&uProcess);
    	
    	while(rProcessFound)
    	{
    		if(strstr(uProcess.szExeFile,process_name)!=NULL)
    		{
    			myproc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, uProcess.th32ProcessID);
    			if(myproc != NULL)
    			{
    				term=TerminateProcess(myproc,0);
    			}
    			CloseHandle(myproc);
    		}
    		rProcessFound=Process32Next(lSnapshot,&uProcess);
    	}
    	CloseHandle(lSnapshot);
    }
    - I'm currently making a process viewer program.
    Last edited by Salem; 06-28-2006 at 01:01 AM. Reason: No font controls in code tags please

  2. #2
    #include<xErath.h> xErath's Avatar
    Join Date
    Jun 2004
    Posts
    722
    You can use the GetModuleFileName, pass a handler to the function to get the full path, but I'm not sure if it accepts process handles. If not you could use Module32First and Module32Next to find the module within a process, and eventually the main program executable wouls show up, therefore matching your string.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to get process info ( to extract process thread id )
    By umen242 in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2009, 12:08 PM
  2. Terminate Process
    By vrkiller in forum C++ Programming
    Replies: 3
    Last Post: 02-10-2009, 04:52 PM
  3. One process with two console windows
    By siavoshkc in forum Windows Programming
    Replies: 8
    Last Post: 01-30-2009, 03:13 PM
  4. Terminate a process
    By cfriend in forum Windows Programming
    Replies: 4
    Last Post: 09-24-2004, 11:56 PM
  5. Threads terminate when parent process does?
    By BigDaddyDrew in forum Windows Programming
    Replies: 1
    Last Post: 04-21-2004, 04:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21