What would the preferred way of programmatically determining which the currently installed version of Microsoft Internet Information Services (IIS) is?
I know that it can be found by looking at the MajorVersion key in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters.
Would this be the recommended way of doing it, or is there any safer or more beautiful method available to a .NET developer?
To identify the version from outside the IIS process, one possibility is like below...
To identify it from within the worker process at runtime...
You could build a WebRequest and send it to port 80 on a loopback IP address and get the Server HTTP header.
Not sure if that's a better way of doing it but it's certainly another option.
No need to write code. You can find it in Registry editor
goto to run -> type - regedit ->
The LOCAL MACHINE Branch of registry contains the Version information for Windows 7.
The Starting Branch is in (HKLM) HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \InetStp\ VersionString
Note: The Spaces are for reading purposes.
The below command helped me find the IIS version correctly on IIS 8.5 (Windows 2012 R2) and 7.5 Windows 7 SP1.
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("$env:SystemRoot\system32\inetsrv\InetMgr.exe").ProductVersion
Reference:
https://forums.iis.net/p/1171695/1984536.aspx : Answer from f00_beard
I did it this way (using Powershell):