toddhd
asked on
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.
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.
most reliable ways that I know of would be these:
Dim rk As Microsoft.Win32.RegistryKe y
Dim SQL As String
Dim IIS As String
rk = Microsoft.Win32.Registry.L ocalMachin e.OpenSubK ey("SOFTWA RE\Microso ft\MSSQLSe rver\MSSQL Server\Cur rentVersio n")
SQL = rk.GetValue("CurrentVersio n")
rk = Microsoft.Win32.Registry.L ocalMachin e.OpenSubK ey("SOFTWA RE\Microso ft\InetStp ")
IIS = rk.GetValue("VersionString ")
MessageBox.Show(SQL & ControlChars.NewLine & IIS)
Dim rk As Microsoft.Win32.RegistryKe
Dim SQL As String
Dim IIS As String
rk = Microsoft.Win32.Registry.L
SQL = rk.GetValue("CurrentVersio
rk = Microsoft.Win32.Registry.L
IIS = rk.GetValue("VersionString
MessageBox.Show(SQL & ControlChars.NewLine & IIS)
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
ASKER
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.
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()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'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
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'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.ListV iew
Friend WithEvents ColumnHeader1 As System.Windows.Forms.Colum nHeader
Friend WithEvents ColumnHeader2 As System.Windows.Forms.Colum nHeader
Friend WithEvents ColumnHeader3 As System.Windows.Forms.Colum nHeader
Friend WithEvents ColumnHeader4 As System.Windows.Forms.Colum nHeader
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.ListView1 = New System.Windows.Forms.ListV iew
Me.ColumnHeader1 = New System.Windows.Forms.Colum nHeader
Me.ColumnHeader2 = New System.Windows.Forms.Colum nHeader
Me.ColumnHeader3 = New System.Windows.Forms.Colum nHeader
Me.ColumnHeader4 = New System.Windows.Forms.Colum nHeader
Me.SuspendLayout()
'
'ListView1
'
Me.ListView1.Columns.AddRa nge(New System.Windows.Forms.Colum nHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3, Me.ColumnHeader4})
Me.ListView1.Dock = System.Windows.Forms.DockS tyle.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.SortO rder.Ascen ding
Me.ListView1.TabIndex = 1
Me.ListView1.View = System.Windows.Forms.View. Details
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "Display Name"
Me.ColumnHeader1.Width = 200
'
'ColumnHeader2
'
Me.ColumnHeader2.Text = "Status"
'
'ColumnHeader3
'
Me.ColumnHeader3.Text = "Service Name"
Me.ColumnHeader3.Width = 200
'
'ColumnHeader4
'
Me.ColumnHeader4.Text = "Type"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(550, 400)
Me.Controls.Add(Me.ListVie w1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
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.GetServi ces
item = ListView1.Items.Add(srvc.D isplayName )
item.SubItems.Add(srvc.Sta tus.ToStri ng())
item.SubItems.Add(srvc.Ser viceName.T oString())
item.SubItems.Add(srvc.Ser viceType.T oString())
Next
End Sub
End Class
Imports System.ServiceProcess
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'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
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'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.ListV
Friend WithEvents ColumnHeader1 As System.Windows.Forms.Colum
Friend WithEvents ColumnHeader2 As System.Windows.Forms.Colum
Friend WithEvents ColumnHeader3 As System.Windows.Forms.Colum
Friend WithEvents ColumnHeader4 As System.Windows.Forms.Colum
<System.Diagnostics.Debugg
Me.ListView1 = New System.Windows.Forms.ListV
Me.ColumnHeader1 = New System.Windows.Forms.Colum
Me.ColumnHeader2 = New System.Windows.Forms.Colum
Me.ColumnHeader3 = New System.Windows.Forms.Colum
Me.ColumnHeader4 = New System.Windows.Forms.Colum
Me.SuspendLayout()
'
'ListView1
'
Me.ListView1.Columns.AddRa
Me.ListView1.Dock = System.Windows.Forms.DockS
Me.ListView1.FullRowSelect
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.SortO
Me.ListView1.TabIndex = 1
Me.ListView1.View = System.Windows.Forms.View.
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "Display Name"
Me.ColumnHeader1.Width = 200
'
'ColumnHeader2
'
Me.ColumnHeader2.Text = "Status"
'
'ColumnHeader3
'
Me.ColumnHeader3.Text = "Service Name"
Me.ColumnHeader3.Width = 200
'
'ColumnHeader4
'
Me.ColumnHeader4.Text = "Type"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(550, 400)
Me.Controls.Add(Me.ListVie
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
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.GetServi
item = ListView1.Items.Add(srvc.D
item.SubItems.Add(srvc.Sta
item.SubItems.Add(srvc.Ser
item.SubItems.Add(srvc.Ser
Next
End Sub
End Class
you would need to check "status" in the loop
ASKER
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( )="IISADMI N" Then
IIS=IIF(srvc.ServiceName.S tatus.ToSt ring()="Ru nning", True, False)
End If
If srvc.ServiceName.ToString( )="MSSQLSE RVER" Then
SQL=IIF(srvc.ServiceName.S tatus.ToSt ring()="Ru nning", True, False)
End If
Dim IIS As Boolean=False
Dim SQL As Boolean=False
If srvc.ServiceName.ToString(
IIS=IIF(srvc.ServiceName.S
End If
If srvc.ServiceName.ToString(
SQL=IIF(srvc.ServiceName.S
End If
sorry for the typo, in both cases it should be > "srvc.Status.ToString()" not "srvc.ServiceName.Status.T oString()"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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! :)
One is to test for a registry key at "HKEY_LOCAL_MACHINE\SYSTEM
"HKEY_LOCAL_MACHINE\SYSTEM
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.D
There are probably other ways too.