Programatically verify IIS is installed and running on XP

Posted on 2005-04-27
Medium Priority
Last Modified: 2008-02-01
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.
Question by:toddhd
  • 8
  • 3

Expert Comment

ID: 13879299
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.
LVL 13

Expert Comment

ID: 13882335
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)
LVL 13

Expert Comment

ID: 13882341
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.


Author Comment

ID: 13884739
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.
LVL 13

Expert Comment

ID: 13885434
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
LVL 13

Expert Comment

ID: 13885438
you would need to check "status" in the loop

Author Comment

ID: 13885571
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.
LVL 13

Expert Comment

ID: 13885607
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

LVL 13

Expert Comment

ID: 13885627
sorry for the typo, in both cases it should be  >  "srvc.Status.ToString()" not "srvc.ServiceName.Status.ToString()"
LVL 13

Accepted Solution

davidlars99 earned 2000 total points
ID: 13885656
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

Author Comment

ID: 13885720
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
LVL 13

Expert Comment

ID: 13885802
then all I have to say is good luck!  :)

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month17 days, 8 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question