Reputation: 2325
Im trying to find some sample code that shows how use the WMI ( using C#) to query a remote IIS 7 for all website bindings. I cant make heads or tails of all the classes/ name spaces and querys that need to be made to accomplish this. If no sample code is available i would love some refrences to good documentation.
Thanks alot
Upvotes: 3
Views: 4119
Reputation: 598
You need to use the ServerManager.OpenRemote("serverName")
function to connect to an external IIS instance. (See the msdn article here.)
If you enumerate through serverManager.Sites
collection you can then retrieve the site.Bindings
property from each Site
object to see the bindings that are active on that website.
Upvotes: 1
Reputation: 32258
You should be able to accomplish this by accessing the IIS metabase, using the System.DirectoryServices assembly.
For example, here you can enumerate through all of your sites and property configurations contained within those sites.
Add this reference to your project:
using System.DirectoryServices
// Assuming your Server Id is 1, and you are connecting to your local IIS.
DirectoryEntry de = new DirectoryEntry(@"IIS://localhost/W3SVC/1/Root");
foreach (DirectoryEntry entry in de.Children)
{
foreach (PropertyValueCollection property in entry.Properties)
{
Console.WriteLine("Name: {0}, Value {1}",property.PropertyName, property.Value);
}
}
Upvotes: 1