I need to get the full path of a file which is opened in an application, by using the process.
For example, I have opened a txt
file from C:\Users\Admin\Documents\sample.txt
in a notepad. Whereas I have two notepad's being opened in desktop. If I used Process.GetProcessesByName("notepad");
I may get all the running instance of notepad and I can even get full path's of running process using Mainmodule.Filename
But my requirement is that I need to get the path of a file (i.e. sample.txt
) from the process. Is it possible?
So for I have tried:
Process[] localByName = Process.GetProcessesByName("EA");
string path = localByName[0].Modules[0].FileName;
foreach (Process process in localByName)
{
}