Process iisreset = new Process();
iisreset.StartInfo.FileName = "iisreset.exe";
iisreset.StartInfo.Arguments = "computer name";
iisreset.Start();
//iisreset.exe is located in the windows\system32 folder.
string processName = "aspnet_wp";
System.OperatingSystem os = System.Environment.OSVersion;
//Longhorn and Windows Server 2003 use w3wp.exe
if((os.Version.Major == 5 && os.Version.Minor > 1) || os.Version.Major ==6)
processName = "w3wp";
foreach(Process process in Process.GetProcessesByName(processName))
{
Response.Write("Killing ASP.NET worker process (Process ID:" +
process.Id + ")");
process.Kill();
}
4条答案
按热度按时间qyyhg6bp1#
lnlaulya2#
mbzjlibv3#
(http://www.velocityreviews.com/forums/t300488-how-can-i-restart-iis-or-server-from-aspx-page-or-web-service.html)(英文)
k4emjkb14#
运行此代码的服务器上是否承载了多个网站?如果是,您可能需要查看System.DirectoryServices命名空间,然后重新启动各个网站