3

I saw some similar questions here, but could not find an answer to my question..

this one almost got it: How to start a 64-bit process from a 32-bit process

But I am missing the explanation regarding how to do it.

I am trying to achieve the following:

P.StartInfo.FileName = "%windir%\\sysnative\\cmd.exe";

but probably doing something wrong - because nothing happens when I Set it this way, but when setting it like this:

P.StartInfo.FileName = "c:\\windows\\sysnative\\cmd.exe";

which I thought is the same - all is working fine. What am I doing wrong?

How can I "tell" the process to resolve the %windir% and not to treat it as is?!

I would just set it as I did in the 2nd example, but I am getting the file name from an outside file which I am not allowed to change, and it is written as %windir%\sysnative\cmd.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
JimmyBoy
  • 351
  • 4
  • 14

2 Answers2

5

Maybe you're just looking for Environment.ExpandEnvironmentVariables?

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.


P.StartInfo.FileName = Environment.ExpandEnvironmentVariables("%windir%\\sysnative\\cmd.exe");
sloth
  • 99,095
  • 21
  • 171
  • 219
2

Your problem has nothing to do with 32 bit or 64 bit... There is no difference in the way you start a new process, the OS figures out, based on the PE headers what type of process it needs when it starts.

Your problem is that environment variables are not expanded in the way you are starting the process. See this answer:

https://stackoverflow.com/a/9675482/61164

Community
  • 1
  • 1
Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291