I'm working with Service Fabric and I would like to create an observer of environment variables of selected processes.
I thought about this method:
var processes = Process.GetProcessesByName(processName);
foreach (var process in processes){
var environmentVariables = process.StartInfo.EnvironmentVariables;
foreach (DictionaryEntry envVar in environmentVariables){
// envVar.Key, enVar.Value ...
}
}
But I can't use StartInfo because processes are not launched here. Is there any other way to retrieve environement variables (key/value) of processes (retrieved by GetProcessByName/ID) ?
Error:
System.InvalidOperationException: Process was not started by this object, so requested information cannot be determined.