I'm trying to retrieve the filename of a current process.
ie: If i have the file "test.txt" opened in Notepad, I need to get something like "c:\folder\test.txt"
The code below returns process informations, including the software path. (ie: "c:\windows\system32\notepad.exe").
[DllImport("user32.dll", EntryPoint = "GetForegroundWindow", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int GetForegroundWindow();
[...]
public static string GetFilePathName()
{
uint procId = 0;
int hWnd = GetForegroundWindow();
GetWindowThreadProcessId(hWnd, out procId);
var proc = Process.GetProcessById((int)procId);
}
Is it possible to use this Process Class to achieve the opened filename/path the the current process is handling?