How to determine the version of IIS

Share on:

It took me far too long to work this out; I needed to know whether or not it was safe to try and set the ManagedPipelineMode property on an AppPool, and I figured the best way to do it would be to check the current IIS version and if it was 7.0 or above. The code to get the current version is straightforward, once you know the names of the properties to read:

1
2DirectoryEntry iisVersionCheck = 
3    new DirectoryEntry("IIS://localhost/W3SVC/Info");
4
5int majorVersion = (int)iisVersionCheck.InvokeGet(
6    "MajorIIsVersionNumber");
7
8int minorVersion = (int)iisVersionCheck.InvokeGet(
9    "MinorIIsVersionNumber");