如何使用c#以编程方式检查服务上的iis版本。
答案 0 :(得分:2)
这是针对IIS 5的答案,它应该适用于当前版本的IIS。
答案 1 :(得分:1)
答案 2 :(得分:-1)
我使用PowerShell做到了这一点。同样的.Net库和类型也可以与C#一起使用:
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
}
}