Как с помощью PID процесса, получить полный путь к файлу?

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by [n]-c0der, 28 Oct 2009.

  1. [n]-c0der

    [n]-c0der Member

    Joined:
    3 Feb 2009
    Messages:
    83
    Likes Received:
    24
    Reputations:
    -1
    сабж, help plz.
     
  2. gold-goblin

    gold-goblin Elder - Старейшина

    Joined:
    26 Mar 2007
    Messages:
    917
    Likes Received:
    174
    Reputations:
    3
    какой язык?
     
  3. [n]-c0der

    [n]-c0der Member

    Joined:
    3 Feb 2009
    Messages:
    83
    Likes Received:
    24
    Reputations:
    -1
    [[C++, Asm, Delphi]]
     
  4. csrss

    csrss Member

    Joined:
    13 Apr 2009
    Messages:
    38
    Likes Received:
    38
    Reputations:
    4
    Code:
    #include <windows.h>
    #include <Psapi.h>
    
    int main(){
        
     int pid = 3432; // PID of notepad.exe
     char buffer[MAX_PATH];
     HANDLE proc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);   
     GetModuleFileNameEx(proc, 0, buffer, MAX_PATH);
    MessageBox(0,buffer,"",0);
    }
    
    Tak chtoli?
     
  5. _nic

    _nic Elder - Старейшина

    Joined:
    5 May 2006
    Messages:
    651
    Likes Received:
    54
    Reputations:
    3
    Кажется вот так:
    Code:
    MODULEENTRY32 me;
    me.dwSize = sizeof(me);
    HANDLE hp;
    hp=CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,pid);
    Module32First(hp,&me);
    cout<<me.szExePath<<endl;
    
     
  6. [n]-c0der

    [n]-c0der Member

    Joined:
    3 Feb 2009
    Messages:
    83
    Likes Received:
    24
    Reputations:
    -1
    ДА в инете точно такой же код нашел, но у меня проблемы с компиляцией первый параметр для GetModuleFileNameEx - не нравится.
     
  7. zeppe1in

    zeppe1in Elder - Старейшина

    Joined:
    12 Jul 2006
    Messages:
    343
    Likes Received:
    66
    Reputations:
    18
    всё ок компилится. psapi.lib подрубил?
     
Loading...