Process对象必须将UseShellExecute属性设置为False才能使用环境变量解决办法

加下面两行
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;

The reason being that the key setting is CreateNoWindow which has to be true. But CreateNoWindow only has any effect when UseShellExecute is false. That’s because CreateNoWindow maps to the CREATE_NO_WINDOW process creation flag passed to CreateProcess. And CreateProcess is only called when UseShellExecute is false.

More information can be found from the documentation:

Property Value

true if the process should be started without creating a new window to contain it; otherwise, false. The default is false.

Remarks

If the UseShellExecute property is true or the UserName and Password properties are not null, the CreateNoWindow property value is ignored and a new window is created.

猜你喜欢

转载自blog.csdn.net/u010178308/article/details/88535563