C# process.start更改环境变量
我有一个批处理文件,正在用C#中的Process.Start()运行。这是我的密码:C# process.start更改环境变量,c#,batch-file,process,environment-variables,C#,Batch File,Process,Environment Variables,我有一个批处理文件,正在用C#中的Process.Start()运行。这是我的密码: Process proc = new Process(); proc.StartInfo.FileName = cmd; proc.StartInfo.Arguments = args; proc.StartInfo.RedirectStandardOutput = false; proc.StartInfo.UseShellExecute = true; proc.Start(); proc.WaitF
Process proc = new Process();
proc.StartInfo.FileName = cmd;
proc.StartInfo.Arguments = args;
proc.StartInfo.RedirectStandardOutput = false;
proc.StartInfo.UseShellExecute = true;
proc.Start();
proc.WaitForExit();
return proc.ExitCode;
当我打开命令行并键入
echo%ProgramFiles%
时,它返回C:\ProgramFiles
。在批处理文件(由C#proc.Start()调用运行)内部,它展开%ProgramFiles%
,并等于C:\ProgramFiles(x86)
。我不明白为什么会发生这种情况,它破坏了我的代码。我如何修复它以及为什么会发生这种情况?很可能是因为您的C代码正在编译为x86,Windows希望保持向后兼容性,因此程序文件指向x86版本
编译为64位,它将指向64位程序文件文件夹
现在,如果你想让你的程序在x86版本的Windows上运行,你需要编译成x86,并为这种情况添加一些手动处理。很可能是因为你的C#代码被编译成x86,Windows希望保持向后兼容性,所以程序文件指向x86版本。编译为64位,它可能会指向64位程序文件文件夹。这很有效!如果你把它作为一个答案,我会接受的。