2

谁能帮我获取以下 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()

非常感谢

4

1 回答 1

2

停止 + 开始 = 回收,所以应该这样做:

参考: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 兼容性”。

于 2012-08-07T10:38:39.117 回答