The ProcessStartInfo.WorkingDirectory property is empty.

I am writing a keep-alive service to find out if a process is running. I have several processes with the same name that end in different working directories.

Therefore, I would like to use the property WorkingDirectoryas a unique identifier. However, when I interrogate all of these properties, the value is empty.

Here is the code:

foreach (Process process in Process.GetProcesses())
    if (!string.IsNullOrWhiteSpace(process.StartInfo.WorkingDirectory))
        Console.WriteLine("Winning!!!");

Needless to say, I am not winning.

+4
source share
1 answer

Use the Process.MainModule and ProcessModule.FileName properties .

foreach (Process process in Process.GetProcesses())
{
    string executableFilePath = process.MainModule.FileName;
    string executableDirectory = Path.GetDirectoryName(executableFilePath);
}

, . "MainModule" , ( ), .

+4

All Articles