Click here to Skip to main content
Click here to Skip to main content
Go to top

Using Managed Code to Detect if IIS is Installed and ASP/ASP.NET is Registered

, 30 Dec 2007
Rate this:
Please Sign up or sign in to vote.
Explains how to use managed code to detect which version of Internet Information Services (IIS) is installed and if ASP or ASP.NET is registered.

Introduction

My earlier article [^] on detecting what .NET Framework versions and service packs are installed using managed code generated some follow up questions related to detecting if Internet Information Services (IIS) is installed and if ASP or ASP.NET is registered.

Since this is a managed code solution, it does require that a version of the .NET Framework is already installed, so this class is not guaranteed to work as part of an installation process. If you need to do this reliably from an installation process, you need to look at doing the same work using unmanaged C++.

Background

The correct way to determine if a specific version of Internet Information Services is installed is to look in the registry for the following key:

HKLM\Software\Microsoft\InetStp\MajorVersion

This is a DWORD value that indicates the version of IIS installed, if it exists.

MajorVersion IIS Version Description
4 IIS 4 Shipped in NT Option Pack for Windows NT 4
5 IIS 5 Shipped in Windows 2000 Server and Windows XP Professional
6 IIS 6 Shipped in Windows Server 2003
7 IIS 7 Shipped in Windows Vista

For IIS 5, you can use the MinorVersion DWORD value to determine if you are running on Windows 2000 Server or Windows XP Professional. If MinorVersion is 1, then you are running on Windows XP Professional.

Detecting IIS Subcomponents

Sometimes, just knowing if IIS is installed isn't enough and you need to determine if specific subcomponents are also installed. Again, we can turn to the registry for this information. All of the subcomponent information is contained in the following registry key:

HKLM\Software\Microsoft\Microsoft\Windows\CurrentVersion\Setup\Oc Manager\Subcomponents

All of the values under this key are DWORDs, so if the value is 1 then that component is installed.

IIS Subcomponent Registry value
IIS common files iis_common
Active Server Pages (ASP) for IIS iis_asp
File Transfer Protocol (FTP) service iis_ftp
IIS Manager (Microsoft Management Console [MMC] snap-in) iis_inetmgr
Internet Data Connector iis_internetdataconnector
Network News Transfer Protocol (NNTP) service iis_nntp
Server-Side Includes iis_serversideincludes
Simple Mail Transfer Protocol (SMTP) service iis_smtp
Web Distributed Authoring and Versioning (WebDAV) publishing iis_webdav
World Wide Web (WWW) service iis_www
Remote administration (HTML) sakit_web
Internet Server Application Programming Interface (ISAPI)
for Background Intelligent Transfer Service (BITS) server extensions
BitsServerExtensionsISAPI
Background Intelligent Transfer Service (BITS)
server extensions snap-in
BitsServerExtensionsManager
FrontPage server extensions fp_extensions
Internet printing inetprint
ActiveX control and sample pages for hosting
Terminal Services client connections over the Web
TSWebClient

Detecting if ASP or ASP.NET is Registered

In order to detect if ASP is registered with IIS, you can simply look to see if the ASP component (iis_asp) is installed. However, for ASP.NET it becomes a little bit more involved since there are different versions of ASP.NET. We can also use the registry for this information, by looking at the following keys:

Framework Version Registry Key
ASP.NET v1.1 HKLM\Software\Microsoft\ASP.NET\1.1.4322.0
ASP.NET v2.0 HKLM\Software\Microsoft\ASP.NET\2.0.50727.0

If the key exists, then that version of ASP.NET is registered with IIS.

Using the Code

In order to consolidate checking all of the various registry keys and help isolate changes for future versions of the .NET Framework and IIS, the InternetInformationServicesDetection class was created. This class exposes the following public methods:

  • public static bool IsInstalled(InternetInformationServicesVersion iisVersion)
  • public static bool IsInstalled(InternetInformationServicesComponent subcomponent)
  • public static bool IsAspRegistered()
  • public static bool IsAspNetRegistered(FrameworkVersion frameworkVersion)

As you can see, these functions use the FrameworkVersion, InternetInformationServicesVersion, and InternetInformationServicesComponent enumerations. These enumerations have the following definition:

/// <span class="code-SummaryComment"><summary></span>
/// Specifies the .NET Framework versions
/// <span class="code-SummaryComment"></summary></span>
public enum FrameworkVersion
{
   /// <span class="code-SummaryComment"><summary></span>
   /// .NET Framework 1.0
   /// <span class="code-SummaryComment"></summary></span>
   Fx10,

   /// <span class="code-SummaryComment"><summary></span>
   /// .NET Framework 1.1
   /// <span class="code-SummaryComment"></summary></span>
   Fx11,

   /// <span class="code-SummaryComment"><summary></span>
   /// .NET Framework 2.0
   /// <span class="code-SummaryComment"></summary></span>
   Fx20,

   /// <span class="code-SummaryComment"><summary></span>
   /// .NET Framework 3.0
   /// <span class="code-SummaryComment"></summary></span>
   Fx30,

   /// <span class="code-SummaryComment"><summary></span>
   /// .NET Framework 3.5 (Orcas)
   /// <span class="code-SummaryComment"></summary></span>
   Fx35,
}

/// <span class="code-SummaryComment"><summary></span>
/// Specifies the Internet Information Services (IIS) versions
/// <span class="code-SummaryComment"></summary></span>
public enum InternetInformationServicesVersion
{
  /// <span class="code-SummaryComment"><summary></span>
  /// Internet Information Services 4
  /// <span class="code-SummaryComment"></summary></span>
  /// <span class="code-SummaryComment"><remarks>Shipped in NT Option Pack for Windows NT 4</remarks></span>
  IIS4,

  /// <span class="code-SummaryComment"><summary></span>
  /// Internet Information Services 5
  /// <span class="code-SummaryComment"></summary></span>
  /// <span class="code-SummaryComment"><remarks>Shipped in Windows 2000 Server and Windows XP Professional</remarks></span>
  IIS5,

  /// <span class="code-SummaryComment"><summary></span>
  /// Internet Information Services 6
  /// <span class="code-SummaryComment"></summary></span>
  /// <span class="code-SummaryComment"><remarks>Shipped in Windows Server 2003</remarks></span>
  IIS6,

  /// <span class="code-SummaryComment"><summary></span>
  /// Internet Information Services 7
  /// <span class="code-SummaryComment"></summary></span>
  /// <span class="code-SummaryComment"><remarks>Shipped in Windows Vista</remarks></span>
  IIS7,
}

/// <span class="code-SummaryComment"><summary></span>
/// Specifies the Internet Information Services (IIS) versions
/// <span class="code-SummaryComment"></summary></span>
public enum InternetInformationServicesComponent
{
  /// <span class="code-SummaryComment"><summary></span>
  /// Internet Information Services Common Files
  /// <span class="code-SummaryComment"></summary></span>
  Common,

  /// <span class="code-SummaryComment"><summary></span>
  /// Active Server Pages (ASP) for Internet Information Services
  /// <span class="code-SummaryComment"></summary></span>
  ASP,

  /// <span class="code-SummaryComment"><summary></span>
  /// File Transfer Protocol (FTP) service
  /// <span class="code-SummaryComment"></summary></span>
  FTP,

  /// <span class="code-SummaryComment"><summary></span>
  /// Internet Information Services Manager
  /// <span class="code-SummaryComment"></summary></span>
  InetMgr,

  /// <span class="code-SummaryComment"><summary></span>
  /// Internet Data Connector
  /// <span class="code-SummaryComment"></summary></span>
  InternetDataConnector,

  /// <span class="code-SummaryComment"><summary></span>
  /// Network News Transfer Protocol (NNTP) service
  /// <span class="code-SummaryComment"></summary></span>
  NNTP,

  /// <span class="code-SummaryComment"><summary></span>
  /// Server-Side Includes
  /// <span class="code-SummaryComment"></summary></span>
  ServerSideIncludes,

  /// <span class="code-SummaryComment"><summary></span>
  /// Simple Mail Transfer Protocol (SMTP) service
  /// <span class="code-SummaryComment"></summary></span>
  SMTP,

  /// <span class="code-SummaryComment"><summary></span>
  /// Web Distributed Authoring and Versioning (WebDAV) publishing
  /// <span class="code-SummaryComment"></summary></span>
  WebDAV,

  /// <span class="code-SummaryComment"><summary></span>
  /// World Wide Web (WWW) service
  /// <span class="code-SummaryComment"></summary></span>
  WWW,

  /// <span class="code-SummaryComment"><summary></span>
  /// Remote administration (HTML)
  /// <span class="code-SummaryComment"></summary></span>
  RemoteAdmin,

  /// <span class="code-SummaryComment"><summary></span>
  /// Internet Server Application Programming Interface (ISAPI) for
  /// Background Intelligent Transfer Service (BITS) server extensions
  /// <span class="code-SummaryComment"></summary></span>
  BitsISAPI,

  /// <span class="code-SummaryComment"><summary></span>
  /// Background Intelligent Transfer Service (BITS) server extensions
  /// <span class="code-SummaryComment"></summary></span>
  Bits,

  /// <span class="code-SummaryComment"><summary></span>
  /// FrontPage server extensions
  /// <span class="code-SummaryComment"></summary></span>
  FrontPageExtensions,

  /// <span class="code-SummaryComment"><summary></span>
  /// Internet printing
  /// <span class="code-SummaryComment"></summary></span>
  InternetPrinting,

  /// <span class="code-SummaryComment"><summary></span>
  /// ActiveX control and sample pages for hosting Terminal Services
  /// client connections over the web
  /// <span class="code-SummaryComment"></summary></span>
  TSWebClient,
}

A complete example in C# looks like this:

bool iis4Installed =
    InternetInformationServicesDetection.IsInstalled
        (InternetInformationServicesVersion.IIS4);

bool iis5Installed =
    InternetInformationServicesDetection.IsInstalled
        (InternetInformationServicesVersion.IIS5);

bool iis6Installed =
    InternetInformationServicesDetection.IsInstalled
        (InternetInformationServicesVersion.IIS6);

bool iis7Installed =
    InternetInformationServicesDetection.IsInstalled
        (InternetInformationServicesVersion.IIS7);


Console.WriteLine("IIS 4 installed? {0}", iis4Installed);
Console.WriteLine("IIS 5 installed? {0}", iis5Installed);
Console.WriteLine("IIS 6 installed? {0}", iis6Installed);
Console.WriteLine("IIS 7 installed? {0}", iis7Installed);

if (iis4Installed || iis5Installed || iis6Installed || iis7Installed)
{
    Console.WriteLine("ASP Registered? {0}",
        InternetInformationServicesDetection.IsAspRegistered());

    Console.WriteLine("ASP.NET 1.0 Registered? {0}",
        InternetInformationServicesDetection.IsAspNetRegistered(FrameworkVersion.Fx10));

    Console.WriteLine("ASP.NET 1.1 Registered? {0}",
        InternetInformationServicesDetection.IsAspNetRegistered(FrameworkVersion.Fx11));

    Console.WriteLine("ASP.NET 2.0 Registered? {0}",
        InternetInformationServicesDetection.IsAspNetRegistered(FrameworkVersion.Fx20));

    // These really don't exist, they are actually the .NET 2.0 version of ASP.NET.
    Console.WriteLine("ASP.NET 3.0 Registered? {0}",
        InternetInformationServicesDetection.IsAspNetRegistered(FrameworkVersion.Fx30));

    Console.WriteLine("ASP.NET 3.5 Registered? {0}",
        InternetInformationServicesDetection.IsAspNetRegistered(FrameworkVersion.Fx35));
}

Points of Interest

The public methods are simply wrappers that determine which private function should be called. These private functions, in turn, query the appropriate registry keys and process the result. However, the real work is done in the GetRegistryValue<T> function. This is a generic function that returns a boolean value indicating if the requested registry key was found and an out parameter that contains the value.

It is important to note that if the user does not have the appropriate permissions to access the registry, this function will throw an exception that will bubble up to the original caller. This was intentionally done to allow the caller the ability to take different actions based on the exception thrown.

Future Considerations

Windows XP 64-bit and Windows Vista 64-bit support. If someone wants to test this on these operating systems and let me know if it runs properly and if not what the errors are, I will correct them.

History

  • 6-April-2007
    • Original article
  • 17-August-2007
    • Updated the download to include fixes to the FrameworkVersionDetection class for the .NET Framework v3.5 Beta 2

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Scott Dorman
Software Developer (Senior)
United States United States
I am a Microsoft C# MVP, author, speaker, blogger, and software developer. I also created the WP Requests and WinStore Requests sites for Windows Phone and Windows Sotre apps as well as several open source projects.
 
I've been involved with computers in one way or another for as long as I can remember, but started professionally in 1993. Although my primary focus right now is commercial software applications, I prefer building infrastructure components, reusable shared libraries and helping companies define, develop and automate process and code standards and guidelines.
Follow on   Twitter   LinkedIn

Comments and Discussions

 
QuestionIIS6 compatibility Pinmemberkiquenet.com13-Jan-14 0:55 
QuestionUpdates for .NET 4.5.1 - IIS 8.5 Pinmemberkiquenet.com13-Jan-14 0:54 
QuestionDoesn't work for me Pinmemberspyhunter99913-Apr-12 15:47 
Generalupdate for Fx40 Pinmemberalhambra-eidos3-Mar-11 1:29 
Generalupdates Pinmemberalhambra-eidos2-Mar-11 4:02 
any updates for Windows 2008, Windows 2008 R2, Windows 7 ??
 

IIS Version Operating Systems Account
 
IIS 5, IIS 5.1
Windows 2000, Windows XP
localmachine\ASPNET
 
IIS 6, IIS 7
Windows 2003, Windows Vista, Windows Server 2008
localmachine\Network Service
 
IIS 7.5
Windows 2008 R2, Windows 7
IIS AppPool\
AE

GeneralI have the ASP.NET registry key even though I do not have IIS installed Pinmemberclaesbrandt7-Aug-08 5:47 
GeneralRe: I have the ASP.NET registry key even though I do not have IIS installed PinmemberJonB14-Aug-08 1:52 
GeneralRe: I have the ASP.NET registry key even though I do not have IIS installed Pinmemberclaesbrandt14-Aug-08 2:18 
GeneralRe: I have the ASP.NET registry key even though I do not have IIS installed PinmemberJonB14-Aug-08 2:50 
GeneralRe: I have the ASP.NET registry key even though I do not have IIS installed PinmemberJonB17-Aug-08 23:01 
GeneralRe: I have the ASP.NET registry key even though I do not have IIS installed Pinmemberclaesbrandt20-Aug-08 10:25 
GeneralRe: I have the ASP.NET registry key even though I do not have IIS installed [modified] PinmemberJonB20-Aug-08 21:32 
GeneralRe: I have the ASP.NET registry key even though I do not have IIS installed Pinmemberclaesbrandt20-Aug-08 21:52 
GeneralRe: I have the ASP.NET registry key even though I do not have IIS installed PinmemberJonB20-Aug-08 22:16 
GeneralRe: I have the ASP.NET registry key even though I do not have IIS installed PinmvpScott Dorman21-Aug-08 5:05 
GeneralRe: I have the ASP.NET registry key even though I do not have IIS installed PinmvpScott Dorman21-Aug-08 5:02 
GeneralRe: I have the ASP.NET registry key even though I do not have IIS installed PinmemberJonB15-Oct-08 6:35 
GeneralRe: I have the ASP.NET registry key even though I do not have IIS installed PinmvpScott Dorman15-Oct-08 8:17 
GeneralRe: I have the ASP.NET registry key even though I do not have IIS installed PinmemberJonB16-Oct-08 1:22 
QuestionDetecting if the subcomponents are enabled Pinmemberradikalee22-Nov-07 15:06 
AnswerRe: Detecting if the subcomponents are enabled PinmvpScott Dorman21-Aug-08 5:08 
GeneralWiX PinmemberLyhr26-Oct-07 11:50 
GeneralRe: WiX PinmemberScott Dorman26-Oct-07 14:01 
GeneralUpdates for .NET Framework 3.5 Beta 2 PinmemberScott Dorman17-Aug-07 16:29 
GeneralPretty Cool Pinmemberhk1116-Aug-07 4:44 
GeneralRe: Pretty Cool PinmemberScott Dorman16-Aug-07 5:20 
QuestionIIS 6.0 Compatibility Mode on Vista PinmemberRazi Mohiuddin16-May-07 20:03 
AnswerRe: IIS 6.0 Compatibility Mode on Vista PinmemberScott Dorman17-May-07 15:41 
AnswerRe: IIS 6.0 Compatibility Mode on Vista Pinmemberparxs1-May-08 7:45 
GeneralLooks good! PinsitebuilderUwe Keim6-Apr-07 8:02 
GeneralRe: Looks good! PinmemberScott Dorman6-Apr-07 8:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 30 Dec 2007
Article Copyright 2007 by Scott Dorman
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid