title: Get the real values of environment variables on a remote machine in .NET
body: <p>I'm trying to get the <strong>actual values</strong> of <strong>environment variables</strong>.<br />This is what I have so far:</p>
  
  <pre><code>string query = string.Format("Select VariableValue From Win32_Environment Where Name = '{0}'", variableName);
  
  using (var searcher = new ManagementObjectSearcher(query))
  using (ManagementObject result = searcher.Get().Cast&lt;ManagementObject&gt;().FirstOrDefault())
  {
      if (result != null)
      return Convert.ToString(result["VariableValue"]);
  }
  </code></pre>
  
  <p>That works, but here's the problem: passing <strong>'windir' as name</strong> gets <strong>'%SystemRoot%' as value</strong>. What I really <strong>want</strong> is the <strong>actual path</strong>, i.e. 'C:\Windows'.</p>
  
  <p>I <strong>tried</strong> using <strong>recursion</strong> to get the <strong>value of 'SystemRoot'</strong> but <strong>no matches</strong> were found.</p>
  
  <p>How can I make sure that the <strong>real values</strong> get returned?<br />Thx!</p>