我看你使用了這項技術。網絡微軟。我認爲您的網站和應用程序由「IIS」託管?
您應該可以使用「DirectoryEntry」及其多個屬性。 你可以這樣做,檢查一個網站或在「ISS」上託管的Web應用程序的狀態,並檢查應用程序池的狀態。
命名空間的使用方法:System.DirectoryServices
(適用於C# & ASP)
約 「的DirectoryEntry」 的更多信息,並將其屬性:DirectoryEntry Info
事情是這樣的:
//Get the webSite ID
public static int GetWebsiteID(string websiteName)
{
string machineName = System.Environment.GetEnvironmentVariable("COMPUTERNAME");
DirectoryEntry w3svc = new DirectoryEntry("IIS://"+machineName+"/w3svc");
int id = 1;
foreach(DirectoryEntry de in w3svc.Children)
{
if(de.SchemaClassName == "IIsWebServer" && de.Properties["ServerComment"][0].ToString() == websiteName)
{
id = int.Parse(de.Name);
}
}
return id;
}
//Check statut of webSite
public void checkStatutWebSite()
{
DirectoryEntry myWebSite = new DirectoryEntry(string.Format("IIS://" + machineName + "/w3svc/{0}/Root", GetWebsiteID("webSiteName")));
ServerState state = (ServerState)Enum.Parse(typeof(ServerState), myWebSite.Properties["ServerState"].Value.ToString())
if (state == ServerState.Stopped || state == ServerState.Paused)
{
//site is stopped
}
}
public enum ServerState
{
Unknown = 0,
Starting = 1,
Started = 2,
Stopping = 3,
Stopped = 4,
Pausing = 5,
Paused = 6,
Continuing = 7
}
我希望這對你有所幫助。
非常感謝以上。是的,我們使用IIS,並會查看System.DirectoryServices,看看我是否可以在VB中使上述情況發生。歡迎您來到 – 2013-05-08 14:28:51
。 – 2013-05-08 14:55:52