开发者

how to check iis version on serve programmatically

开发者 https://www.devze.com 2023-01-02 21:04 出处:网络
how to check iis vers开发者_开发百科ion on serve programmaticallyusing c#.This was answered for IIS 5, it should work with current version of IIS.

how to check iis vers开发者_开发百科ion on serve programmatically using c#.


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

How to detect IIS version using C#?


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


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
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消