15,510,771 members
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
Posted

## Solution 1

I can help get you started:

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

OpenProcess[^]

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

GetProcessImageFileName[^]

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.

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
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

## Solution 2

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>

Source:http://msdn.microsoft.com/en-us/library/6sehtctf.aspx

v2