我在程序中调用了Rar.exe以及批处理。但是在我关闭程序后内存中会有许多的Rar.exe 和cmd.exe 
请问怎么处理啊?
程序中用的是ShellExecute很WinExec.

解决方案 »

  1.   

    BOOL CFindKillProcess::FindProcess(CString ExeFile)
    {
    BOOL ResultValue;
    CString FileName;
    HANDLE Handle=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
        ProcessInfo.dwSize=sizeof(PROCESSENTRY32);

    ExeFile= ExeFile.Left(15);
    ExeFile.MakeLower();
    ResultValue= false;
    if(Process32First(Handle,&ProcessInfo))
    {
    if(GetLastError()!=ERROR_NO_MORE_FILES )
    {
    FileName.Format("%s",ProcessInfo.szExeFile);
    FileName= FileName.Left(15);
    FileName.MakeLower();
    if (strcmp(FileName,ExeFile))
    {

    while(Process32Next(Handle,&ProcessInfo)!=FALSE)
    {
    FileName.Format("%s",ProcessInfo.szExeFile);
    FileName= FileName.Left(15);
    FileName.MakeLower();
    if (strcmp(FileName,ExeFile)==0)
    {
    ResultValue= true;
    break;
    }
    }
    }
    else ResultValue= true;
    }
    }
    CloseHandle(Handle);
    return ResultValue;
    }BOOL CFindKillProcess::KillProcess(BOOL bZap)
    {
    // 我已经关闭了全部主窗口,现在等待进程死亡。 
        BOOL bKilled = TRUE;
    //    HANDLE hp=OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE,FALSE,ProcessInfo.th32ProcessID);
        HANDLE hp=OpenProcess(PROCESS_ALL_ACCESS,TRUE,ProcessInfo.th32ProcessID);
    int rc = GetLastError();
        if (hp) {
            if (WaitForSingleObject(hp, 5000) != WAIT_OBJECT_0) {
                if (bZap) { // 不愿死,那不行,你必须死
                    TerminateProcess(hp,0);
                } else {
                    bKilled = FALSE;
                }
            }
            CloseHandle(hp);
        }
        return bKilled;
    }参考上面的函数,手动清除吧
      

  2.   

    //得到当前路径
    TCHAR *path = new char[MAX_PATH+1];
    GetModuleFileName(::GetModuleHandle(NULL),path,MAX_PATH);
    INIFilePath = path; // 当前的路径名+你的程序名
    INIFilePath.TrimRight("\\Current Path.exe");

    CString tmp;
    for(int i = 0 ; i <m_List1.GetCount();i++)
    {
    if (m_List1.GetSel(i))
    {
    m_List1.GetText(i,tmp);
    }
    }
    int slen = tmp.Find("*");
    sss1.Format("rar");
    tn = zz.TrimRight(".rar");
    sss2.Format(" x %s *.* %s\\",zz,tn);
    ::ShellExecute(NULL,NULL,sss1,sss2,INIFilePath,SW_HIDE);
    Sleep(250);
    这个是调用rar.exe 释放文件。