title: Starting a program with dynamic path in C#
body: <p>I have created software that start's a program in my AppData folder. </p>
  
  <p>What I wanted to do however is to let it run with a dynamic path. </p>
  
  <p>The current path I used is: </p>
  
  <pre><code>new ProcessStartInfo(@"C:\Users\user\AppData\Local\SOFTWAREPROGRAM\File\program.exe")
  </code></pre>
  
  <p>I want it however to make it possible to not just run on 'user' but on all users with the AppData folder. I tried the following path (which works when browsing in directories):</p>
  
  <pre><code>new ProcessStartInfo(@"%USERPROFILE%\AppData\Local\SOFTWAREPROGRAM\File\program.exe")
  </code></pre>
  
  <p>With this however, I get the 'file not found'-error. </p>
  
  <p>How would I correct this? I want it to work on different users. </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The answer works in my program but doesn't work in the service I'm trying to develop. I have tried:</p>
  
  <p>(the answer)</p>
  
  <pre><code>new ProcessStartInfo(Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\AppData\Local\SOFTWAREPROGRAM\File\program.exe"))
  </code></pre>
  
  <p>and</p>
  
  <pre><code>string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  string specificFile = Path.Combine(folder, @"\Local\SOFTWAREPROGRAM\File\program.exe");
  
  ProcessStartInfo(specificFile)
  </code></pre>
  
  <p>This works in a program (console project) but not in a service. Why is this?</p>
  
  <p>I output the specificFile while running but it only contains <code>\Local\SOFTWAREPROGRAM\File\program.exe</code> </p>