谁能帮我在下面的vbscript代码的c#中获取代码。
Option Explicit
Dim WebSiteID, objWebSite, ObjAppPool
WebSiteID = "1"
Set objWebSite = GetObject("IIS://localhost/W3SVC/" & WebSiteID)
WScript.Echo "Stopping Web Site : " & objWebSite.ServerComment
objWebSite.Stop()
wscript.echo "Stopping Application Pool : " & objWebSite.AppPoolID
Set objAppPool = GetObject("IIS://localhost/W3SVC/AppPools/" & objWebSite.AppPoolID)
objAppPool.Stop()
wscript.echo "Starting Application Pool : " & objWebSite.AppPoolID
objAppPool.Start()
WScript.Echo "Starting Web Site : " & objWebSite.ServerComment
objWebSite.Start()
非常感谢
最佳答案
停止+开始=回收,所以应该这样做:
参考:System.DirectoryServices.dll
using System.DirectoryServices;
void Recycle(string appPool)
{
var appPoolPath = "IIS://localhost/W3SVC/AppPools/" + appPool;
using (DirectoryEntry appPoolEntry = new DirectoryEntry(appPoolPath))
{
appPoolEntry.Invoke("Recycle", null);
appPoolEntry.Close();
}
}
如果此方法失败,则可能需要在服务器上启用“ IIS 6 WMI兼容性”。