Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1049135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:34:04+00:00 2026-05-16T16:34:04+00:00

To sum it up, I need to do this: 12345(hWnd) -> C:\setup.exe Right now,

  • 0

To sum it up, I need to do this:

12345(hWnd) -> “C:\setup.exe”


Right now, I am using GetProcessImageFileName to retrieve the Kernel Device Path of a process handle. I’m retrieving the handle using OpenProcess, passing it the PID. The PID (which I also need) is being retrieved using GetWindowThreadProcessId.

However, this gets me to a string like:

\Device\Harddisk1\setup.exe

At this point, I enumerate all drives on the system using DriveInfo.GetDrives(), and then call QueryDosDevice. Finally, I can do some string-manipulation magic, and “boom,” I have my path.


Ok, so my issues:

  1. This process breaks down on Network drives.
  2. All I really want is QueryFullProcessImageName on XP

There HAS to be a better way to do this. Please enlighten me, oh gods of WIN32API!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:34:05+00:00Added an answer on May 16, 2026 at 4:34 pm

    The obvious question would be why you don’t just use QueryFullProcessImageName, if that’s what you want? Do you need compatibility with older versions of Windows?

    The closest equivalent to QueryFullProcessImageName that’s available on XP is probably GetModuleFileNameEx. I’d probably detect whether QueryFullProcessImageName is available and use it if possible, otherwise fall back to GetModuleFileNameEx.

    Edit: While GetModuleFileNameEx isn’t 100% dependable at retrieving the name of the executable for every possible process, it does work at least a fairly substantial part of the time. Here’s a quick bit of test code I put together:

    #include <windows.h>
    #include <psapi.h>
    #include <iterator>
    #include <iostream>
    #include <string>
    #include <map>
    
    std::string getfilename(DWORD pid) { 
        HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, pid);
        static int winver;
        char path[256]= {0};
        DWORD size = sizeof(path);
    
        if (winver==0) 
            winver = GetVersion() & 0xf; 
    
    #if WINVER >= 0x600
        if (winver >= 6)    
            QueryFullProcessImageName(process, 0, path, &size);
        else
    #endif
        if (!GetModuleFileNameEx(process, NULL, path, sizeof(path)))
            strcpy(path, "Unknown");
        return std::string(path);
    }
    
    typedef std::map<DWORD, std::string> win_map;
    
    namespace std { 
        ostream &operator<<(ostream &os, win_map::value_type const &v) { 
            return os << v.first << ": " << v.second;
        }
    }
    
    BOOL CALLBACK show_info(HWND window, LPARAM lParam) {
        win_map &exes = *(win_map *)lParam;
    
        DWORD pid;
        GetWindowThreadProcessId(window, &pid);
        exes[pid] = getfilename(pid);
        return true;
    }
    
    int main() {
        win_map exes;
        EnumWindows(show_info, (LPARAM)&exes);
        std::copy(exes.begin(), exes.end(), std::ostream_iterator<win_map::value_type>(std::cout, "\n"));
        return 0;
    }
    

    The results of a quick test are somewhat interesting. Compiled as 32-bit code, the version using QueryFullProcessImageName found 33 processes with top-level windows, and found names for 31 of those executables. The version using GetModuleFileNameEx, also found 33 processes, but only found names for 21 of the executable. If, however, I compile it as 64-bit code, either version finds filenames for 31 out of 33 executables (and the same two fail). Given the frequency with which you see XP/x64, that’s probably of little consequence, but I found it interesting nonetheless.

    In any case, even the least capable version (32-bit/GMFNE) found names for ~2/3rds of the files. While that’s certainly not what you’d hope for, it’s certainly better than nothing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to select unique codes and their sum(value) values. This does not work:
I need to query this DB to get each row, but also the SUM
I need to parseFloat this then to replace the dot with a comma: sum=<?php
I have one field that I need to sum lets say named items However
I need sphinx to sort the results by the sum of an attribute. I
I need to write a non-recursive version of the function sum-squares and Use a
I've a need to add method that will calculate a weighted sum of worker
Given the XML below, I need to group by InputItem and sum the costs
I have three MySQL queries I need to combine into a single query using
I need to change this trigger to point to the column that just got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.