我看你使用了这项技术。网络微软。我认为您的网站和应用程序由“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