Click here to Skip to main content
15,608,404 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

I have some opened directories and application appear in taskbar. How to get path of them?

For example: There are 1 opened directory: C:\Windows and 2 application D:\Data\Word.doc and D:\Data\text.txt.

I want to get path of them by their Window Handle by calling EnumWindow

Do you have any solution?

Thank you

I can help get you started:

Start by querying for the processID that owns the window you are querying


Then open a handle with PROCESS_QUERY_INFORMATION access to the process:


With the process handle, you can get the name of the application that is running the process:


To actually get the path of some open file, it will most likely be program dependent for your information to be reliable. Possibly Explorer.exe changes the working directory for the current folder, but I dont know for sure. Document based programs you could possibly look at the open file handles for that process, but there is no guarantee for that either.

For Word and MS Office based apps specifically, I would investigate their scripting objects. They will most likely be able to report which document they are using for each process instance.
Share this answer
SVPro 13-Nov-11 0:16am    
Thank Paul,

but there is a linking error: [Linker error] undefined reference to 'GetProcessImageFileName' (Dev-C)

I included "psapi.h" but above error still appear.
Paul M Watt 13-Nov-11 0:47am    
In that case you will just need to add the .lib file into your linker settings on the properties dialog for your project, linker tab, input settings.
Here are the names listed based on the operating system you are using on the reference page for the API:

Kernel32.lib on Windows 7 and Windows Server 2008 R2;
Psapi.lib if PSAPI_VERSION=1 on Windows 7 and Windows Server 2008 R2;
Psapi.lib on Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP/2000

Good Luck
SVPro 13-Nov-11 1:18am    
Where's Psapi.lib?
I added Psapi.dll from system32 but there's nothing, it's the same error
Paul M Watt 13-Nov-11 1:44am    
What compiler are you using?

You will need to search for psapi.lib on your machine, and make sure that directory is included in your compiler linker settings. Then you should just be able to reference the llib file. Linking against the dll will not work.

If you are using a compiler that does not have psapi.lib, you can still dynamically load the psapi.dll, and then user GetProcAddress to load the functions and call them that way. linking is easier if you can find the lib file.
SVPro 13-Nov-11 1:56am    
I'm using Dev-C
You probably getting an error because you didn't specify version of windows api you want.

Example to enable windows 7 level api:

#define WINVER 0x0601
#include <windows.h>

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900