For some odd reaseon this code fails:
p.StartInfo.FileName = @"%temp%\SSCERuntime_x86-ENU.msi";
and this code succes:
p.StartInfo.FileName = @"C:\Users\USERNAME\AppData\Local\Temp\SSCERuntime_x86-ENU.msi";
Is there any reason I am missing?
Note I just copied the path, I don't think the rest of the code is needed but I'll put it anyway:
Process p = new Process();
p.StartInfo.FileName = @"%temp%\SSCERuntime_x86-ENU.msi";
p.StartInfo.Arguments = "/passive";
p.Start();
Try this:
Then concat it in:
Casper beat me to the punch on the explaination, but the Process.Start method basically treats it literally instead of intrperting it as the shell would.
%TEMP% is parsed and evaluated by Command Shell. You could use use Path.GetTempPath() and Path.Combine for this purpose.
You can use the
Environment.ExpandEnvironmentVariables
to expand environment variables within a string, then pass that to theProcess
class:This has the added benefits of
The
Process
class does not expand strings with environment variables (i.e.%temp%
).If you want to use environment variables to build the
FileName
property then you'll have to get the environment variables (using theGetEnvironmentVariable
method on theEnvironment
class) and perform the substitution yourself, like so:Additionally, you can use the
ExpandEnvironmentVariables
method with your original string like so:The
%temp%
portion of the string is being interpreted literally instead of being replaced with the appropriate environment variable. You'll need to manually expand it