Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I ensure C#'s Process.Start will expand environment variables?

I'm attempting to create a process like so:

var psi = new ProcessStartInfo
{
    FileName = @"%red_root%\bin\texturepreviewer.exe",
    UseShellExecute = true
};

var process = Process.Start(psi);
process.WaitForExit();

Now the environment variable "red_root" definitely exists in the spawned process' environment variables, but the execute doesn't seem to expand the environment variable and so the file isn't found. How can I get the Process.Start to expand the environment variable in the file name?

like image 386
MattN Avatar asked Dec 08 '10 14:12

MattN


People also ask

Does walking prevent C-section?

Does Walking and Exercise Prevent C-Sections? According to a study published in the British Journal of Sports Medicine, women who participated in moderate exercise during pregnancy were 34% less likely to have a cesarean delivery than their non-exercising counterparts.

Can I shave before C-section?

Your health care provider might ask you to shower at home with an antiseptic soap the night before and the morning of your C-section. Don't shave your pubic hair within 24 hours of your C-section. This can increase the risk of a surgical site infection.


1 Answers

The Environment.ExpandEnvironmentVariables method should help here.

Replaces the name of each environment variable embedded in the specified string with the string equivalent of the value of the variable, then returns the resulting string.

string unexpandedPath = "%red_root%\\bin\\texturepreviewer.exe";   
psi.FileName = Environment.ExpandEnvironmentVariables(unexpandedPath);
like image 104
Ani Avatar answered Sep 27 '22 16:09

Ani