Killing a process.

This is a discussion on Killing a process. within the Windows Programming forums, part of the Platform Specific Boards category; [windows 98] How do I go about killing a process running, which is not visible in the Windows Task Manager, ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220

    Killing a process.

    [windows 98]
    How do I go about killing a process running, which is not visible in the Windows Task Manager, when I have the process file name? (i.e.) mega.exe . (I want to be able to do this with my program).

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

  3. #3
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Originally posted by RoD
    Use the kill method:

    http://msdn.microsoft.com/library/de...skilltopic.asp
    That's only if you're using .NET, I believe.

    http://www.google.com/search?hl=en&i...=Google+Search

    I'd like to help you more, but my mind's drawing a blank. I believe there's a TerminateProcess() function in windows.h, but I know you need the handle of the process, and I can't remember how to get that. Sorry.

  4. #4
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    hmm i'm not sure either, it said windows98 in the platform list so i assumed it would, i think theres a line like

    hProcess = openprocess(CLOSE_PROCESS, TRUE, <name of process)

    something like that, i know i've seen it. Lemme look round google some.

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    I would use EnumProcesses() to get the process ID, then OpenProcess() to get it's handle, then TerminateProcess() to kill it, but I'd have to have a really good reason for doing so as it can be dangerous.

    Look at those functions in the help or MSDN.

    Of course, if I wanted to run a process that could not be tracked, I would have "mega.exe" just create and launch another process, so the process name had nothing in common with the file name.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by adrianxw
    I would use EnumProcesses() to get the process ID, then OpenProcess() to get it's handle, then TerminateProcess() to kill it, but I'd have to have a really good reason for doing so as it can be dangerous.
    You could also enumerate processes with Process32First() and Process32Next().
    This is better because the structure returned by these functions contains the name of the exe file.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> You could also enumerate processes with Process32First() and Process32Next().


    Yup, you certainly could, but again, if you only know the name of the executable your launched, you may not find it in the current processes. If I was being "stealthy" I would have the launched process basically a dummy who's sole purpose in life was to launch other processes. Kill the launcher - but the spy is still there, <fx> X files music </fx>.

    I tend to use EnumProcesses() because that is always the way I have done it. In many cases, there are more than one way to do things with mature operating systems. I don't know, but I wouldn't mind guessing that Process32First() does what I am doing internally.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    ˇAmo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Yeah, you could take a snapshot using CreateToolhelp32Snapshot.

    Then, use Process32First and after that, use Process32Next.

    When going through the Processes, check if the process name equals the one that you are looking for.

    If you find it, use OpenProcess with the Process ID that is in your PROCESSENTRY32 struct to open the process.

    From here, call TerminateProcess with the handle that you get from OpenProcess.


    For an explanation, check here

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. init adopts zombie process?
    By password636 in forum Linux Programming
    Replies: 4
    Last Post: 07-01-2009, 10:05 AM
  2. Killing A Process
    By tommyb05 in forum C Programming
    Replies: 8
    Last Post: 06-01-2009, 06:41 AM
  3. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  4. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 01:43 AM
  5. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM

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