Display Windows Services in VB.NET

You are currently viewing Display Windows Services in VB.NET

.NET Framework provides System.ServiceProcess namespace that contains classes developers can use to create and install Windows Services. These classes include ServiceBase, ServiceInstaller and ServiceProcessInstaller. This namespace also contains one class which can display the list of all the Windows Services running on local or remote computer. In this tutorial I will show you how you can display the list of locally running Windows Services in VB.NET.

You can write following code at Form load even to populate listbox control with all locally running Windows Services. You need to import System.ServiceProcess namespace for the code example below.

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) 
    Dim localServices As ServiceController() = ServiceController.GetServices() 
    For Each service As ServiceController In localServices 
        listBox1.Items.Add(service.DisplayName) 
    Next 
End Sub

Write following code at listbox SelectedIndexChanged Event to get information about currently selected Windows Service.

Private Sub listBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    Dim localServices As ServiceController() = ServiceController.GetServices()
    Dim service As ServiceController = localServices(listBox1.SelectedIndex)
   
    label4.Text = service.DisplayName
    label5.Text = service.ServiceName
    label6.Text = service.Status.ToString()
End Sub
READ ALSO:  Read Database Connection Strings from App.Config

This Post Has 6 Comments

  1. Ibrahim ALzaidi

    please how can i start or restart or stop Services on my computer by app vb.net

    and how i can do it for remote computer

    thanks

  2. Bradley

    Great Tutorial Thank you for your time and help very well presented. 5*

  3. Vikas Ajit Medhekar

    Thanks for the great information. I was actually searching for a source code in VB.NET that helps me not only list the Windows Services but also manage them (i.e. enable, disable), etc.

    By the way, nice article and keep it up!

  4. Polas

    Thank you very much i helped me this is what i needed it 😉

  5. Srinath Santhanagopalan

    I need to start a particular services from the Database can u provide a sample

  6. arvinth

    sir,
    i Create a Windows service in vb.net .by using the system i insert the time value for every one Milli Second
    after restart of the System the time Doesn’t inserted on the database ,what is the Problem

Leave a Reply