title: How to get other process's environment variable using c#
body: <p>I have an <strong>elevated process</strong> and I'm trying to extract an environment variable from another process using C#. I know that the variable exists by using Process Explorer.</p>
  
  <p>I can get the process environment variables like the following:</p>
  
  <pre><code>Process process = Process.GetProcessesByName("someprocess").First();
  string value = process.StartInfo.EnvironmentVariables["var_name"];
  </code></pre>
  
  <p>But <strong><a href="https://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&amp;l=EN-US&amp;k=k(System.Diagnostics.Process.StartInfo);k(SolutionItemsProject);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5.1);k(DevLang-csharp)&amp;rd=true" rel="nofollow">StartInfo</a> only returns a subset of the process env variables, passed to process.Start()</strong>.</p>
  
  <p>How can I get environment variables that have bee set during process run time?</p>