views:

21

answers:

0

Hello everybody!

I need to get IIS web-site state programmatically via C#. I usually do it this way:

DirectoryEntry DE = new DirectoryEntry( string.Format( "IIS://localhost/W3SVC/{0}", siteID ) );
Int32 serverState = (Int32)DE.Properties["ServerState"][0];
if ( serverState == IISHelper.MD_SERVER_STATE_STOPPED )
     DE.Invoke("Start", new object[] { });

But this code does't work on Windows Vista, serverState is always 4 (Stopped) even if the site is running and DE.Invoke("Start", new object[] { }) throws Interop exception.

How can i do this on Vista?

Thanks.