向大家请教一个问题:如果已经启动了一道进程,如启动了netmeeting在另外一个自己编写程序中,如何终止该netmeeting。

解决方案 »

  1.   

    TerminateProcessThe TerminateProcess function terminates the specified process and all of its threads.
    BOOL TerminateProcess(
      HANDLE hProcess,
      UINT uExitCode
    );Parameters
    hProcess 
    [in] Handle to the process to terminate. 
    Windows NT/2000/XP:  The handle must have the PROCESS_TERMINATE access right. For more information, see Process Security and Access Rights.uExitCode 
    [in] Exit code to be used by the process and threads terminated as a result of this call. Use the GetExitCodeProcess function to retrieve a process's exit value. Use the GetExitCodeThread function to retrieve a thread's exit value. 
      

  2.   

    先查找进程的HANDLE然后调用TerminateProcess
      

  3.   

    先查找相关进程窗口得到窗口句柄,再用GetWindowThreadProcessId()得到其ID,再用OpenProcess()得到其句柄,就可以用TerminateProcess()结束之
      

  4.   

    先查找相关进程窗口得到窗口句柄,再用GetWindowThreadProcessId()得到其ID,再用OpenProcess()得到其句柄,就可以用TerminateProcess()结束之
      

  5.   

    // 查找已经存在的要关闭的进程进行关闭
    DWORD ProcessID[50];
    CString kkk[50];
    HANDLE SnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); 
    PROCESSENTRY32* info=new PROCESSENTRY32;
    PROCESSENTRY32 ProcessInfo;//声明进程信息变量
    ProcessInfo.dwSize=sizeof(ProcessInfo);//设置ProcessInfo的大小
    //返回系统中第一个进程的信息
    BOOL Status=Process32First(SnapShot,&ProcessInfo);
    int m_nProcess=0;
    /////////////////////////////////////////////////////// 
    while(Status)
    {
    CString s,str1,str2;
    s.Format("%d",ProcessInfo.cntThreads);
    str1.Format("%s",ProcessInfo.szExeFile);
    str1=ProcessInfo.szExeFile;
    kkk[m_nProcess]=ProcessInfo.szExeFile; 
    ProcessID[m_nProcess]=ProcessInfo.th32ProcessID; 
    //////////////////////////////////////////////////////
    if(str1=="****.exe")
    {
    HANDLE ProcessHandle;
    ProcessHandle=OpenProcess (PROCESS_ALL_ACCESS,FALSE,ProcessID[m_nProcess]);
    TerminateProcess(ProcessHandle,0);
    }
    Status=Process32Next(SnapShot,&ProcessInfo);
    m_nProcess++;

    ///////////////////////////最后记得加入头文件
    #include "TLHELP32.H"//一定要加如这个头文件
      

  6.   

    void EnableDebugPriv()
    {
    HANDLE hToken;
    LUID sedebugnameValue;
    TOKEN_PRIVILEGES tkp;

    if ( ! OpenProcessToken( GetCurrentProcess(),
    TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) )
    {
    AfxMessageBox("openprocesstoken");
    return;
    }
    if ( ! LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &sedebugnameValue ) ){
    CloseHandle( hToken );
    {
    AfxMessageBox("close handle");
    return;
    }
    }
    tkp.PrivilegeCount = 1;
    tkp.Privileges[0].Luid = sedebugnameValue;
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    if ( ! AdjustTokenPrivileges( hToken, FALSE, &tkp, sizeof tkp, NULL, NULL ) )
    {
    CloseHandle( hToken );
    }
    }EnableDebugPriv();
    TerminateProcess(OpenProcess(PROCESS_TERMINATE ,FALSE,进程号,0);
    /*
    函数:取得进程列表
    */
    void CSystemInfo::ListProcess()
    {   
    CString m_proc;
    HANDLE         hProcessSnap;
    HANDLE         hModuleSnap;
        PROCESSENTRY32 pe32={0};  
    MODULEENTRY32  me32={0};

        hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);  
        if (hProcessSnap == (HANDLE)-1) 
    {
    return;
    }
        pe32.dwSize = sizeof(PROCESSENTRY32);  
        if (Process32First(hProcessSnap, &pe32))  
        {  
            do
            {  
    if(GetVersion()&0x80000000)
    {
    CString strpro;
    CString pstrpro;
    char MName[_MAX_PATH];
    char EXT[_MAX_PATH];
    ::_splitpath(pe32.szExeFile,NULL,NULL,MName,EXT);

    pstrpro.Format("%s%s",MName,EXT);
    strpro.Format("%d%s%s%s%s%s",pe32.th32ProcessID,"$",pstrpro,"#",pe32.szExeFile,"@");
    m_proc+=strpro;

    }
    else
    {
    if(pe32.th32ProcessID>8)
    {
    hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,pe32.th32ProcessID);
    if(hModuleSnap!=(HANDLE)-1)
    {
    me32.dwSize=sizeof(MODULEENTRY32);
    if(Module32First(hModuleSnap,&me32))
    {
    CString strpro;
    CString pstrpro;
    char MName[_MAX_PATH];
    char EXT[_MAX_PATH];
    ::_splitpath(pe32.szExeFile,NULL,NULL,MName,EXT);

    pstrpro.Format("%s%s",MName,EXT);
    strpro.Format("%d%s%s%s%s%s",pe32.th32ProcessID,"$",pstrpro,"#",me32.szExePath,"@");
    m_proc+=strpro;
    }
    CloseHandle(hModuleSnap);
    }
    }
    }
            }while (Process32Next(hProcessSnap, &pe32));
        }  
    CloseHandle (hProcessSnap);
    }