Posted by: jwalin on: December 13, 2007
you can get the IIS Version programically by using following way. If you are using Windows 2003 or Windows Vista then you can get by using
DirectoryEntry dirRoot = new DirectoryEntry(IISRoot);
DirectoryEntry child = dirRoot.Children.Find(“Info”, “IIsWebInfo”);
foreach (PropertyValueCollection c in child.Properties)
{
if (string.Compare(c.PropertyName, “MajorIIsVersionNumber”, StringComparison.CurrentCultureIgnoreCase) == 0)
{
return Convert.ToInt16(c.Value, CultureInfo.InvariantCulture);
}
}
But if you are using windows XP then It is difficult to get because it store in a binary. So I tried following way to get the IIS Version and in my case it works fine.
try
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + @”\inetsrv\inetinfo.exe”);
Console.WriteLine(“Version:” + fvi.FileVersion +”\nMajor Part: ” + fvi.FileMajorPart + “.” + fvi.FileMinorPart);
}
catch (FileNotFoundException ex)
{
throw ex;
}
November 6, 2009 at 4:45 pm
Doesn’t work with IIS7 (default config on Windows 7 and 2008) because no ADSI anymore.