zoukankan      html  css  js  c++  java
  • Kill Process by Name

    Kill Process by Name
    (works in: Microsoft Windows 95/98/ME/NT/2000/XP)
    It is sometimes necessary to terminate a running process in MS-Windows. The Win32 API provides the TerminateProcess function for this, but it requires a "handle to the process". In many cases it is not apparent how to get this handle if all you know is the process name. The following routine lets you get around this problem.

    The routine is named KILL_PROC_BY_NAME, and is available as part of the C++ source file EXAM28.CPP. The routine has the following calling parameters:


    int KILL_PROC_BY_NAME(const char *)
    where the process name is supplied as a zero-terminated C char string and it returns an integer completion code.
    You can download the file in ZIP format by clicking on the following link.

    Download Exam28.zip (3 kB, last modified: 3/10/2002)
    This works for Microsoft Windows 95/98/ME/NT/2000/XP. I have tested with Visual C++ v6.0 but it should work with other versions also. Please let me know of exceptions.

    After downloading, unzip the file Exam28.cpp into any folder. It contains a short console mode program which demonstrates how to call KILL_PROC_BY_NAME to terminate the NotePad program.

    Change history:

    3/10/2002 - Fixed memory leaks as suggested by Jonathan Richard-Brochu and also made Borland C compatible as suggested by Bob Christensen.
    Note: This routine uses the Windows API function TerminateProcess to terminate the process. This may not be suitable for all purposes. In particular, note the following remarks from the MSDN description of TerminateProcess.

    Remarks (on TerminateProcess)

    The TerminateProcess function is used to unconditionally cause a process
    to exit. Use it only in extreme circumstances. The state of global data
    maintained by dynamic-link libraries (DLLs) may be compromised if
    TerminateProcess is used rather than ExitProcess.

    TerminateProcess causes all threads within a process to terminate,
    and causes a process to exit, but DLLs attached to the process are not
    notified that the process is terminating.

    Terminating a process causes the following:

    1. All of the object handles opened by the process are closed.

    2. All of the threads in the process terminate their execution.

    3. The state of the process object becomes signaled, satisfying any
    threads that had been waiting for the process to terminate.

    4. The states of all threads of the process become signaled, satisfying
    any threads that had been waiting for the threads to terminate.

    5. The termination status of the process changes from STILL_ACTIVE to
    the exit value of the process.

    Terminating a process does not cause child processes to be terminated.

    Terminating a process does not necessarily remove the process object
    from the system. A process object is deleted when the last handle to the
    process is closed.
    If you have any questions please send them to the e-mail address below.

    Further Reading:

    Howto Enumerate Applications in Win32 (Microsoft KB article)

    Disclaimer:
    This site contains some software that I've written over the years. It is believed to work, but there is no warranty. Please use at your own risk. If you notice any bugs please let me know by email at kochhar@physiology.wisc.edu.

    Return to Ravi's Free Software Page
    Return to Ravi's Home Page
    Back to The Basement
    This page last modified on : Mar. 10, 2002

    http://www.physiology.wisc.edu/ravi/software/killproc/

  • 相关阅读:
    多线程简略版
    vue组件,vue补充和总结,JS循环遍历和加减运算、类型转换补充
    表单、条件、循环指令,分隔符,前端数据库,过滤器,计算属性,监听属性,冒泡排序
    vue基本语法 JS补充
    VUE框架
    跨站请求伪造(csrf),django的settings源码剖析,django的auth模块
    cookie和session django中间件
    多对多第三张表的创建方式 和 forms组件的使用
    golang之 Array(数组)
    变量,数据类型,运算符,流程控制
  • 原文地址:https://www.cnblogs.com/micro-chen/p/5937563.html
Copyright © 2011-2022 走看看