我试图通过获取以'abc'开始的池列表来更改池设置,然后使用System.Diagnostics.Process.Start更改参数。在本例中,将其改为32位。
class Program
{
static void Main(string[] args)
{
Process.Start(new ProcessStartInfo
{
Arguments = "list apppool /name:$="*abc*" /xml | c:\Windows\System32\inetsrv\appcmd set apppool /in /enable32BitAppOnWin64:true",
FileName = "appcmd.exe",
WorkingDirectory = Environment.GetEnvironmentVariable("SystemRoot") + @"system32inetsrv",
WindowStyle = ProcessWindowStyle.Hidden
});
}
}
我遇到的问题是管道内部的参数。我不太确定这是否允许,语法上应该是什么样子。如有任何帮助,不胜感激。
如果将第一个命令的输出读入当前进程,然后将其写入第二个命令,可能会更容易。像这样:
Process first = new Process();
first.StartInfo.UseShellExecute = false;
first.StartInfo.RedirectStandardOutput = true;
first.StartInfo.FileName = "c:\Windows\System32\inetsrv\appcmd";
first.StartInfo.WorkingDirectory = Environment.GetEnvironmentVariable("SystemRoot") + @"system32inetsrv";
first.StartInfo.Arguments = "list apppool /name:$="*abc*" /xml";
first.Start();
string output = first.StandardOutput.ReadToEnd();
first.WaitForExit();
// now put into the second
Process second = new Process();
second.StartInfo.FileName = "c:\Windows\System32\inetsrv\appcmd.exe";
second.StartInfo.WorkingDirectory = Environment.GetEnvironmentVariable("SystemRoot") + @"system32inetsrv";
second.StartInfo.Arguments = "set apppool /in /enable32BitAppOnWin64:true";
second.StartInfo.UseShellExecute = false;
second.StartInfo.RedirectStandardInput = true;
second.Start();
second.StandardInput.Write(output);
second.StandardInput.Close();
second.WaitForExit();