Calling IIsWebServer.Status via ADSI and C#
09 November 2005
The IIS ADSI Provider reference (incorrectly) states that IIsWebServer.Status is a method call, but the following code snippet fails with HRESULT 0x80020003.
DirectoryEntry ent =
new DirectoryEntry("IIS://localhost/W3SVC/1");
// next call throws
// System.Runtime.InteropServices.COMException (0x80020003): Member not found.
int status = (int) ent.Invoke("Status",null);
It happens that IIsWebServer.Status is actually a property and the proper calling mechanism would be :
DirectoryEntry ent =
new DirectoryEntry("IIS://localhost/W3SVC/1");
Object ads = ent.NativeObject; Type type = ads.GetType();
int status = (int)type.InvokeMember("Status",
BindingFlags.GetProperty,
null, ads, null);
blog comments powered by Disqus