Skip to content

Instantly share code, notes, and snippets.

@mishrsud
Last active August 29, 2015 14:25
Show Gist options
  • Save mishrsud/64c8bf372c901860cc83 to your computer and use it in GitHub Desktop.
Save mishrsud/64c8bf372c901860cc83 to your computer and use it in GitHub Desktop.
Reads IIS Version of the registry
/// <summary>
/// Gets the IIS version from registry.
/// </summary>
/// <remarks>
/// From SO: http://stackoverflow.com/a/1699947/190476
/// </remarks>
public Version GetIisVersion()
{
using (RegistryKey componentsKey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\InetStp", false))
{
if (componentsKey != null)
{
int majorVersion = (int)componentsKey.GetValue("MajorVersion", -1);
int minorVersion = (int)componentsKey.GetValue("MinorVersion", -1);
if (majorVersion != -1 && minorVersion != -1)
{
return new Version(majorVersion, minorVersion);
}
}
return new Version(0, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment