Skip to content

How to extract filename information from running processes ?

Aditya Mangla

Asked May 23, 2007, 5:15 AM EDT1 answer
Share
LinkedInX
Hi :-) I am creating a software that will save the present state of all the applications running on the desktop (WinXP). Can anyone point out the method to extract the filenames from the handles (or otherwise) of the files that are being accessed by processes and programs ? For example : If I have opened xyz.docx in MS Word 2007 then I want to find out the name of the file ("xyz.docx") and its complete path through some mean which could be either : 1. Reading or extracting information from the Word 2007 process handle. 2. Through another non- handle based general method. Kindly help ! Regards, Aditya

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0

    The code below will get the filepath from the running Word Process

    using System.Diagnostics;

    static void Main(string[] args)

    {

    GetProcessPath("WinWord");

    // GetAllProcessPaths();

    Console.ReadLine();

    }

    private static void GetProcessPath(string appProcessName)

    {

    Process[] processes = Process.GetProcessesByName(appProcessName);

    string filePath = processes[0].Modules[0].FileName;

    Console.WriteLine(filePath);

    }

    0