【发布时间】:2013-01-20 01:40:05
【问题描述】:
我需要在 Windows server 2003 的 IIS 6 中通过其名称获取网站的 ID。我使用 C# 完成此操作,但后来发现服务器没有安装 .Net 框架。我只知道网站的名称。
string directoryEntry = string.Format("IIS://localhost/w3svc");
var w3Svc = new DirectoryEntry(directoryEntry);
foreach (DirectoryEntry de in w3Svc.Children) {
if (de.SchemaClassName == "IIsWebServer" && de.Properties["ServerComment"][0].ToString() == "MyWebsiteName") {
Environment.ExitCode = Convert.ToInt32(de.Name);
return;
}
}
int id = Process.Start("MyApp.exe");
我必须运行一个批处理文件才能在远程机器上启动和停止网站。我可以使用PSexec 运行批处理来启动和停止网站,但我不知道如何动态获取网站的 ID。有人可以帮我解决这个问题吗?
如果我不够清楚或需要提供更多信息,请告诉我。
【问题讨论】:
标签: iis batch-file web iis-6 identifier