问题
i've written a code to retrieve list of IIS services on a remote computer, now I am trying to retrieve information about the .svc file of the web service. The code below works for all the services that are stored in the inetpub folder, but i know it is not necessary to store the services there and it can be saved anywhere.
public static void IISWebSvcLister(string Hos)
{
try
{
string s = null;
Hos = Hos.Trim();
DirectoryEntry w3svc = new DirectoryEntry("IIS://" + Hos + "/w3svc/1/root");
foreach (DirectoryEntry de in w3svc.Children)
{
if (de.Children.ToString() != null)
{
s += de.Name.ToString() + "\n";
//string sp = HttpContext.Current.Server.MapPath(@"~\\"+Hos+"\c$\inetpub\wwwroot\");
try
{
string[] filePaths = Directory.GetFiles(@"\\" + Hos + @"\c$\inetpub\wwwroot\" + de.Name.ToString(), "*.svc", SearchOption.AllDirectories);
for (int i = 0; i < filePaths.Length; i++)
{
FileInfo fi = new FileInfo(filePaths[i]);
Console.Write(fi.CreationTime.ToString() + "\t" + fi.Length.ToString());
string[] k = filePaths[i].Split('\\');
filePaths[i] = k[k.Length-2]+"\\"+k[k.Length - 1];
Console.WriteLine("\t" + filePaths[i]);
}
}
catch (Exception)
{
Console.WriteLine(de.Name.ToString());
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
How do i get the files for the services not stored in c:\inetpub\wwwroot ?
Thanks
来源:https://stackoverflow.com/questions/6491198/get-svc-file-info-of-iis-web-service-on-remote-computer