Programatically verify IIS is installed and running on XP

I am writing a install program that takes care of some of the tasks involved in installing and confguring an ASP.NET website. As part of the process, I'd like to very that IIS and SQL Server are installed and running. I have most of this process down - I wrote some functions that will take a Service Name as a parameter, and it will spit back whether the service exists, and is running. For example, to check is SQLServer is installed, I pass the value "MSSQLSERVER", as this is the service name that you see when you look in Admin Tools | Services.

What I don't seem to be able to find is which service relates directly to IIS. I do see a service called IIS Admin, and another called Word Wide Web Publishing, and I'm not sure if either of these is the exact IIS service? Maybe it is something else?

I guess this is an easy question, but I just can't figure out which one is correct. If you happen to know, or could point me to some documentation that explains it, I'd appreciate it.
Who is Participating?
following might be useful

[Service name]       [DisplayName]
Iisadmin            IIS Admin Service
Msftpsvc            FTP Publishing Service
Nntpsvc            Microsoft NNTP Service
Smtpsvc           Microsoft SMTP Service
W3svc                   World Wide Web Publishing Service
There are a couple ways you could go about doing it.  

One is to test for a registry key at "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\MajorVersion" and
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\MinorVersion" (the one for SQL Server is at "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\CurrentVersion")

You could also check for the folder "%systemdir%\inetsrv"

You can also use Active Directory to test if IIS is exists and is running:

System.DirectoryServices.DirectoryEntry iisRoot = new System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/");

There are probably other ways too.
most reliable ways that I know of would be these:

Dim rk As Microsoft.Win32.RegistryKey
Dim SQL As String
Dim IIS As String

rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\MSSQLServer\MSSQLServer\CurrentVersion")
SQL = rk.GetValue("CurrentVersion")

rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\InetStp")
IIS = rk.GetValue("VersionString")

MessageBox.Show(SQL & ControlChars.NewLine & IIS)
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

if such values and keys don't exist in the registry then it means NOT INSTALLED and SQL and IIS values will be none! after that you can just check agains empty values with IF... ELSE... END IF
toddhdAuthor Commented:
davidlars99  - Thanks - that would likely tell me if it is installed, but would not indicate if it is running.
BurntSky - that probably looks right - I never thought of testing the IIS:// path, which would indeed probably indicate that IIS is at least running. Let me double check. I'm surprised that there appears to be way to directly check a service. I *think* I can just check if the IISAdmin service is running, as that is what starts and stops IIS, but I don't know if IIS can keep running without it. I'll have to stop it, and then see what happens.
in that case you have to dive into windows services and check it from there, copy and paste this code and see what you get

Imports System.ServiceProcess

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()

        'This call is required by the Windows Form Designer.

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
            End If
        End If
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader
    Friend WithEvents ColumnHeader4 As System.Windows.Forms.ColumnHeader
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ListView1 = New System.Windows.Forms.ListView
        Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader
        Me.ColumnHeader4 = New System.Windows.Forms.ColumnHeader
        Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3, Me.ColumnHeader4})
        Me.ListView1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.ListView1.FullRowSelect = True
        Me.ListView1.LabelEdit = True
        Me.ListView1.Location = New System.Drawing.Point(0, 0)
        Me.ListView1.Name = "ListView1"
        Me.ListView1.Size = New System.Drawing.Size(400, 312)
        Me.ListView1.Sorting = System.Windows.Forms.SortOrder.Ascending
        Me.ListView1.TabIndex = 1
        Me.ListView1.View = System.Windows.Forms.View.Details
        Me.ColumnHeader1.Text = "Display Name"
        Me.ColumnHeader1.Width = 200
        Me.ColumnHeader2.Text = "Status"
        Me.ColumnHeader3.Text = "Service Name"
        Me.ColumnHeader3.Width = 200
        Me.ColumnHeader4.Text = "Type"
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(550, 400)
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim item As ListViewItem
        For Each srvc As ServiceController In ServiceController.GetServices
            item = ListView1.Items.Add(srvc.DisplayName)
    End Sub

End Class
you would need to check "status" in the loop
toddhdAuthor Commented:
Thanks davidlars99 - If you check the original question, I already have a routine which will grab the service and check the status - the question is - what is the direct name of the IIS service? I can't seem to find it. I only seem to see services that support IIS, such as IIS Admin and World Wide Web Publishing - I don't think either of those is the actual IIS service itself.
you have to check against "srvc.ServiceName.ToString()" and I think IIS name is "IISADMIN" and SQL name is "MSSQLSERVER"

Dim IIS As Boolean=False
Dim SQL As Boolean=False

If srvc.ServiceName.ToString()="IISADMIN" Then
     IIS=IIF(srvc.ServiceName.Status.ToString()="Running", True, False)
End If

If srvc.ServiceName.ToString()="MSSQLSERVER" Then
     SQL=IIF(srvc.ServiceName.Status.ToString()="Running", True, False)
End If

sorry for the typo, in both cases it should be  >  "srvc.Status.ToString()" not "srvc.ServiceName.Status.ToString()"
toddhdAuthor Commented:
Thanks David - you gave me the most info, and I think I'll play around with those services to make sure which one is accurate
then all I have to say is good luck!  :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.