Getting process name + path from PID

Posted on 2006-04-22
Last Modified: 2012-08-14
Hello experts,

I need the image name and path from a PID. I found this example code on MSDN's site, but I'm having some trouble with it.

I'm using VC 2005 Express and it wont compile without a typecast on the 3rd parameter of GetModuleFileNameEx. If I do type cast it as (LPWSTR), then I run into stack curruption. When it does run, I only get a single char returned "C", without the path or image name.

Can someone please help me out here, I just need to resolve random PID's to image/path.

Question by:mugman21
    LVL 48

    Accepted Solution

    char szModName[MAX_PATH];

    Replace with:

    TCHAR szModName[MAX_PATH];
    wchar szModName[MAX_PATH];

    VC++ 8.0 creates Unicode applications by default.
    If you don't want Unicode, you can change Character Set parameter in the Project Settings.
    LVL 8

    Author Comment

    Well, that was stupid :-)


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now