如何找到那个进程并结束他,又不影响自己?

解决方案 »

  1.   

    我在要结束的程序中注册了一些东西,用TerminateProcess没注销掉,下次启动就不行了,还有没有其他方法?
      

  2.   

    //there is some code ,maybe you should change some
    DWORD GetProcessIdFromName(LPCTSTR name)
    {
       PROCESSENTRY32 pe;
    DWORD id = 0;
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    pe.dwSize = sizeof(PROCESSENTRY32);
    if( !Process32First(hSnapshot,&pe) )
    return 0;
    while(1)
    {
    pe.dwSize = sizeof(PROCESSENTRY32);
    if( Process32Next(hSnapshot,&pe)==FALSE )
    break;
    if(strcmp(pe.szExeFile,name) == 0)
    {
    id = pe.th32ProcessID;
    break;
    }

    };
    CloseHandle(hSnapshot);
    return id;
    }
    GetProcessIdFromName("agent.exe")如果不为0就存在