Here is how I do it in AutoHotkey:
GetWindowsExplorerSelectedFile(_hWnd)
{
local selectedFiles, file
; I can send ^C and parse Clipboard, but this way don't mess with clipboard at all, seems nicer.
; Warning: with this, you get only what is displayed in Explorer!
; If you kept the default Windows setting of not displaying file extensions (bad idea...),
; you will get partial file names...
ControlGet, selectedFiles, List, Selected Col1, SysListView321, ahk_id %_hWnd%
Loop, Parse, selectedFiles, `n ; Rows are delimited by linefeeds (`n).
{
If (A_Index = 1)
{
file := A_LoopField
}
Else
{
; Indicate that several files are selected, we return only the first one
; but count the total number of selected files, to indicate we return a partial result
ErrorLevel := A_Index
}
}
Return file
}
And I get the path from the edit field of the Explorer (which is prone to problems! Can be absent or can be set up not to display full path).
The core idea is to ask the SysListView32 control of Explorer what are the selected items, and get them.
Now, that's a hack, there are probably cleaner ways...
PS.: Also found this: Getting ListView items in C# from SysListView32 using SendMessage
Need some voodoo to get it working on another process...
Real code at a French site!