我正在开发一个调用外部流程的应用程序,如下所示:

ProcessStartInfo startInfo = new ProcessStartInfo(PathToExecutable, Arguments){
     ErrorDialog = false,
     RedirectStandardError = true,
     RedirectStandardOutput = true,
     UseShellExecute = false,
     CreateNoWindow = true,
     WorkingDirectory = WorkingDirectory
 };

using (Process process = new Process()) {
    process.StartInfo = startInfo;

    process.Start();
    process.BeginErrorReadLine();
    process.BeginOutputReadLine();
    process.WaitForExit();

    return process.ExitCode;
}

我要调用的过程之一取决于我不希望用户设置的环境变量。有什么方法可以修改发送到外部进程的环境变量?理想情况下,我只能使它们仅对正在运行的进程可见,但是如果我必须以编程方式在全系统范围内设置它们,则我会为此感到满意(但是,UAC会迫使我以管理员身份运行吗? )

ProcessStartInfo.EnvironmentVariables是只读的,因此很多帮助是...

最佳答案

不过,您可以为其添加值。

MSDN ProcessStartInfo.EnvironmentVariables Property:

关于c# - 将自定义环境变量传递给System.Diagnostics.Process,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13255745/

10-11 17:37