Process p = new Process();
                p.StartInfo = new ProcessStartInfo
                {
                    FileName = @"c:\windows\system32\inetsrv\AppCmd.exe",
                    Arguments = "recycle apppool /apppool.name:xxx",
                    CreateNoWindow = true,
                    UseShellExecute = false,
                    RedirectStandardOutput = false,
                    RedirectStandardError = false
                };
                p.EnableRaisingEvents = true;
                p.Start();
                p.WaitForExit();

或者下面方法

using Microsoft.Web.Administration;

var
result = ""; ServerManager sm = new ServerManager(); var pool = sm.ApplicationPools["xxx"]; if (pool != null && pool.State == ObjectState.Stopped) { if (pool.Start() == ObjectState.Started) { result += "start ok!"; } } if(pool!=null && pool.State == ObjectState.Started) { if (pool.Recycle() == ObjectState.Started) { result += "recyle ok!"; } }

下面的方法,在无权限的时候,可以试试

进程里看w3wp对应的id是否有变化来判断是否重启成功,重启逻辑应该是先新增一个,再删除旧的,刚回收时,会同时存在两个进程。

相关文章:

  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2020-06-04
  • 2022-12-23
猜你喜欢
  • 2021-07-26
  • 2021-06-04
  • 2021-07-16
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案