11

how to check iis version on serve programmatically using c#.

Cœur
  • 37,241
  • 25
  • 195
  • 267
rajshades
  • 511
  • 4
  • 9
  • 21
  • possible duplicate of [How to detect IIS version using C#?](http://stackoverflow.com/questions/446390/how-to-detect-iis-version-using-c) – James Jun 08 '10 at 13:38

3 Answers3

2

This was answered for IIS 5, it should work with current version of IIS.

How to detect IIS version using C#?

Community
  • 1
  • 1
sholsapp
  • 15,542
  • 10
  • 50
  • 67
1

http://www.codeproject.com/KB/cs/iisdetection.aspx this express how, you should query the registry

Oscar Cabrero
  • 4,168
  • 8
  • 29
  • 49
-1

I did this using powershell. The same .Net libs and types can be used with C# as well:

function Validate-IISVersion([switch] $ContinueOnError = $false)
{

    if ($ContinueOnError)
    { $ErrorActionPreference = "SilentlyContinue" }
    else
    { $ErrorActionPreference = "Stop" }

    # Using GAC to ensure the IIS (assembly) version
    $IISAssembly = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
    $IISVersion = $IISAssembly.GetName().Version
    $IISVersionString = [string]::Format("{0}.{1}.{2}.{3}", $IISVersion.Major, $IISVersion.Minor, $IISVersion.Build, $IISVersion.Revision)
    if (!$IISVersionString.Equals("7.0.0.0"))
    {
        if ($ContinueOnError)
        {
            Write-Host  "`nConflicting IIS version found! [Version: $IISVersionString]`t    " -NoNewline -ForegroundColor Red
        }
        Write-Error "Conflicting IIS version found [$IISVersionString]! @ $(Split-Path $MyInvocation.ScriptName -leaf)"
        return $false
    }
    else
    {
        return $true
    }
}
Vaibhav
  • 2,527
  • 1
  • 27
  • 31