我想作一个进程管理器。
现在的问题是:如何由进程id得到进程的全路径名?

解决方案 »

  1.   

    根据进程ID得到句柄后(用下面的函数得到)
    HANDLE OpenProcess(
      DWORD dwDesiredAccess,  // access flag
      BOOL bInheritHandle,    // handle inheritance option
      DWORD dwProcessId       // process identifier
    );
    再用GetModuleFileName()函数。
    ----------------------------
    在98下可以用:
    void GetProcessPath(DWORD ProcessID,CString ProcessPath)
    {
    HANDLE hSnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPALL,NULL);
    PROCESSENTRY32 pEntry;
    pEntry.dwSize =sizeof(pEntry);
    BOOL hRes=Process32First(hSnapShot,&pEntry);
    while(hRes)
    {
    if(ProcessID==pEntry.th32ParentProcessID)
    ProcessPath = pEntry.szExeFile;
    hRes=Process32Next(hSnapShot,&pEntry);
    }
    }
      

  2.   


    hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
    用GetModuleFileNameEx可以得到进程路径,比GetModuleFileName功能要强些
    不过还是有部分系统进程不能得到