![](/img/trans.png)
[英]Process.Start() totally ignore the environment variables in PATH
[英]process.start changes 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.WaitForExit();
return proc.ExitCode;
當我打開命令行並鍵入echo %ProgramFiles%
它將返回C:\\Program Files
。 在批處理文件(正在通過C#proc.Start()調用運行)內部,它擴展%ProgramFiles%
並等於C:\\Program Files (x86)
。 我不知道為什么會這樣,並且正在破壞我的代碼。 我該如何解決它,為什么會發生呢?
很有可能是因為您的C#代碼被編譯為x86,而Windows希望保持向后兼容性,因此Program Files指向x86版本。
編譯為64位,它將指向64位Program Files文件夾。
現在,如果您希望程序在x86版本的Windows上運行,則需要將其編譯為x86並為此情況添加一些手動處理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.