HANDLE hProcess;
hProcess=OpenProcess(dwProcessId);
TerminateProcess(hProcess,0);
CloseHandle(hProcess); //you don't want to use hProcess no longer

解决方案 »

  1.   

    这样可以没距进程
    ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    HANDLE hSnapShot=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    PROCESSENTRY32 thePE;//保存进程的信息
    thePE.dwSize=sizeof(PROCESSENTRY32);
    HANDLE hProcess=(HANDLE)::Process32First(hSnapShot,&thePE);
    ::Process32Next(hSnapShot,&thePE);然后使用楼上的方法终止就可以了
      

  2.   

    FlyingSch(FlyingSch) 
    说的方法很不错,我试过了,除了一点小问题基本可以成功。
    我改成如下样子:HANDLE hProcess;
    hProcess=OpenProcess(1,0,dwProcessId);
    TerminateProcess(hProcess,0);
    CloseHandle(hProcess); //you don't want to use hProcess no longer
      

  3.   

    gboy(hello)兄:
    你的程序应该怎么调试,好象很经典,至少比我枚举那部分简单多了!!
    能不能给一个完全的源程序——你给的那部分我调试过,说是没有你的那个
    CreateToolhelp32Snapshot成员。
    小弟很弱,所以还是请高手详细解释。每部分最好有个解释,还有使用方法,我怕我不会用,导致调试的时候出错,谢了!!!
      

  4.   

    #include "Tlhelp32.h"
    ………………………………………………
    CArray<PROCESSENTRY32,PROCESSENTRY32> m_PEArray;
    CListBox m_MyList
    ………………………………………………
    void CFileDlg::OnButton1() 
    {
    m_PEArray.RemoveAll();
    m_MyList.ResetContent();
    HANDLE hSnapShot=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    PROCESSENTRY32 thePE;
    thePE.dwSize=sizeof(PROCESSENTRY32);
    HANDLE hProcess=(HANDLE)::Process32First(hSnapShot,&thePE);
    m_PEArray.Add(thePE);
    m_MyList.AddString(thePE.szExeFile);
    for (int i=1;;i++)
    {
    if (::Process32Next(hSnapShot,&thePE)==FALSE)
    break;
    m_PEArray.Add(thePE);
    m_MyList.AddString(thePE.szExeFile);
    }

    }
      

  5.   

    gboy(hello) 兄,不好意思,还是出错。
    我用VC 6 键了一个 MFC APPWIZARD   标准对话框工程
    在EnumProDlg.cpp中输入如下:
    //代码开始#include "stdafx.h"
    #include "EnumPro.h"
    #include "EnumProDlg.h"
    #include "Tlhelp32.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CEnumProDlg dialog
    CArray<PROCESSENTRY32,PROCESSENTRY32> m_PEArray;
    CListBox m_MyList;CEnumProDlg::CEnumProDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CEnumProDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CEnumProDlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }void CEnumProDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CEnumProDlg)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CEnumProDlg, CDialog)
    //{{AFX_MSG_MAP(CEnumProDlg)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CEnumProDlg message handlersBOOL CEnumProDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here

    return TRUE;  // return TRUE  unless you set the focus to a control
    }// If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.void CEnumProDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }
    }// The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CEnumProDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }void CEnumProDlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    m_PEArray.RemoveAll();
    m_MyList.ResetContent();
    HANDLE hSnapShot=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    PROCESSENTRY32 thePE;
    thePE.dwSize=sizeof(PROCESSENTRY32);
    HANDLE hProcess=(HANDLE)::Process32First(hSnapShot,&thePE);
    m_PEArray.Add(thePE);
    m_MyList.AddString(thePE.szExeFile);
    for (int i=1;;i++)
    {
    if (::Process32Next(hSnapShot,&thePE)==FALSE)
    break;
    m_PEArray.Add(thePE);
    m_MyList.AddString(thePE.szExeFile);
    }
    }
    //仍然报错,如下:
    EnumProDlg.cpp
    D:\Downloads\service\EnumPro\EnumProDlg.cpp(19) : error C2143: syntax error : missing ';' before '<'
    D:\Downloads\service\EnumPro\EnumProDlg.cpp(19) : error C2501: 'CArray' : missing storage-class or type specifiers
    D:\Downloads\service\EnumPro\EnumProDlg.cpp(19) : error C2143: syntax error : missing ';' before '<'
    D:\Downloads\service\EnumPro\EnumProDlg.cpp(104) : error C2065: 'm_PEArray' : undeclared identifier
    D:\Downloads\service\EnumPro\EnumProDlg.cpp(104) : error C2228: left of '.RemoveAll' must have class/struct/union type
    D:\Downloads\service\EnumPro\EnumProDlg.cpp(110) : error C2228: left of '.Add' must have class/struct/union type
    D:\Downloads\service\EnumPro\EnumProDlg.cpp(116) : error C2228: left of '.Add' must have class/struct/union type
    Error executing cl.exe.EnumPro.exe - 7 error(s), 0 warning(s)
    我知道,可能是我比较笨,但还望gboy(hello) 兄,能帮我完成这个工作,谢了!如果能调成的话,我会加分得。谢谢。
      

  6.   

    多谢各位的帮助,小弟终于调成功了!最后两个问题:
    1.CArray<PROCESSENTRY32,PROCESSENTRY32> m_PEArray 
       CArray 类怎么用?
       mPEArray.Add(thePE);      //向mPEArray中加一个数据
       如何从中得到一个数据,是  mPEArray.GetData  么,我不太会,能不能 
       给个例子。
    2.如何向m_MyList中加入整形数据?
        m_MyList.AddString();
        好象不行,我想将   thePE.The32ProcessId 
        也加如到m_MyList中。
      
        谢了谢了谢了!!!
    两个小问题不敢立项,所以不得不等找到答案再结分了。抱歉之至!!
      

  7.   

    问题终于得到解决了,BBS的实在了不起
    在此感谢gboy(hello)和FlyingSch(FlyingSch) 的帮助,特别是gboy(hello) 这段时间以来不断给与耐心的解答。