Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect IIS version using C#?

Tags:

c#

iis

How to detect IIS version using C#?

Update: I meant from a winapp (actually the scenario is developing a custom installer that wants to check the version of the installed IIS to call the appropriate api's)

like image 787
Amr Elsehemy Avatar asked Jan 15 '09 11:01

Amr Elsehemy


People also ask

How do I determine IIS version?

Type inetmgr into the textbox and press Enter on your keyboard (you can also type %SystemRoot%\system32\inetsrv\InetMgr.exe instead and press Enter). The Internet Information Services (IIS) Manager window will appear. Go to Help -> About Internet Information Services to find IIS version.

What is the latest version of IIS?

IIS 10.0 is the latest version of Internet Information Services (IIS) which shipped with Windows 10 and Windows Server 2016. This article describes the new functionality of IIS on Windows 10 and Windows Server 2016 and provides links to resources to learn more about these features.

What version of IIS is on Windows Server 2022?

Windows Server 2022 natively supports HTTP/3 with Internet Information Services (IIS). Brandon Lee has been in the IT industry 15+ years and focuses on networking and virtualization. He contributes to the community through various blog posts and technical documentation primarily at Virtualizationhowto.com.


4 Answers

Found the answer here: link text The fileVersion method dosesn't work on Windows 2008, the inetserv exe is somewhere else I guess.

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

I tested it, it works perfectly on Windows XP, 7 and 2008

like image 85
ErTelis Avatar answered Oct 05 '22 05:10

ErTelis


You can get this information from the SERVER_SOFTWARE variable. It will return the following:

Microsoft-IIS/5.0 (Windows 2000)
Microsoft-IIS/5.1 (Windows XP)
Microsoft-IIS/6.0 (Windows 2003 Server)

etc.

If you're using ASP.NET, you can get this string via

Request.ServerVariables["SERVER_SOFTWARE"];

EDIT: It seems that you will have to query the registry to get this information. Take a look at this page to see how.

like image 29
Igal Tabachnik Avatar answered Oct 05 '22 05:10

Igal Tabachnik


This is how i do it.

FileVersionInfo verinfo = FileVersionInfo.GetVersionInfo(System.Environment.SystemDirectory + @"\inetsrv\inetinfo.exe");

//Tip... look at verinfo.MajorVersion.
like image 31
Jesper Palm Avatar answered Oct 05 '22 05:10

Jesper Palm


U can find it in the registry.

Up to IIS version 6 you can find it here:

HKLM\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters

Since version 7 here:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp

MajorVersion MinorVersion

like image 36
Xn0vv3r Avatar answered Oct 05 '22 07:10

Xn0vv3r