Jwalin Khatri

Dynamically / Programatically get IIS Version

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

1 Response to "Dynamically / Programatically get IIS Version"

Doesn’t work with IIS7 (default config on Windows 7 and 2008) because no ADSI anymore.

Leave a Reply

Blog Stats

  • 15,522 hits

  • Bob: Doesn't work with IIS7 (default config on Windows 7 and 2008) because no ADSI anymore.
  • jwalin: Follow the following steps 1]. open you Page in NOTEPAD. 2]. find the tag 3]. Replace the "body" like body oncontextmenu=”return false;" 4]. Sav
  • cytocine: Halu , how to put that , i mean where to put the part ?? i really dont know i hope you can help me out thanks..