code_junkie

How to detect IIS version using C#

Nov 13th, 2011
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. Request.ServerVariables["SERVER_SOFTWARE"];
  2.  
  3. FileVersionInfo verinfo = FileVersionInfo.GetVersionInfo(System.Environment.SystemDirectory + @"inetsrvinetinfo.exe");
  4.  
  5. //Tip... look at verinfo.MajorVersion.
  6.  
  7. public Version GetIisVersion()
  8. {
  9. using (RegistryKey componentsKey =
  10. Registry.LocalMachine.OpenSubKey(@"SoftwareMicrosoftInetStp", false))
  11. {
  12. if (componentsKey != null)
  13. {
  14. int majorVersion = (int)componentsKey.GetValue("MajorVersion", -1);
  15. int minorVersion = (int)componentsKey.GetValue("MinorVersion", -1);
  16. if (majorVersion != -1 && minorVersion != -1)
  17. {
  18. return new Version(majorVersion, minorVersion);
  19. }
  20. }
  21. return new Version(0, 0);
  22. }
  23. }
Add Comment
Please, Sign In to add comment