none
How Can I get "Description" in Windows Services? RRS feed

  • Question

  • Hi,

    I am writing VB.NET code (Windows Forms) for displaying Windows Services.  I can get ServiceName, DisplayName, Status, StartType, but cannot "Description".  How can I get it?
     

    Here's my code for displaying services in DataGridView.
    Dim scSvcs() As ServiceController = ServiceController.GetServices()
    Dim sc As ServiceController
    Dim myRow As Integer = 0
    For Each sc In scSvcs
    	Me.dgv_List.Rows.Add()
    	Me.dgv_List(0, myRow).Value = sc.Status
    	Me.dgv_List(1, myRow).Value = sc.ServiceName
    	Me.dgv_List(2, myRow).Value = sc.DisplayName
    	Me.dgv_List(3, myRow).Value = sc.StartType
    	Me.dgv_List(4, myRow).Value = "??? Description ???"	' <== This is what I want to get
    	myRow += 1
    Next
    Best Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Wednesday, September 25, 2019 7:28 AM

Answers

  • Hi Ashidacchi,

    Add the code after Me.dgv_List(3, myRow).Value = sc.StartType

    Dim wmiService As New ManagementObject("Win32_Service.Name='" + sc.ServiceName + "'")
    wmiService.Get()
    value = wmiService("Description")
    Me.dgv_List(5, myRow).Value = value

    Thanks and Best Regards,

    E-John

    • Marked as answer by Ashidacchi Wednesday, September 25, 2019 9:49 AM
    Wednesday, September 25, 2019 8:48 AM

All replies

  • Hi Ashidacchi,

    Imports System.Management
    Imports System.ServiceProcess
    
    Public Class Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim scSvcs() As ServiceController = ServiceController.GetServices()
            Dim title As String = ""
            Dim value As String = ""
            Dim result As String = ""
    
            For Each sc In scSvcs
                If (sc.Status = ServiceControllerStatus.Stopped) Then
    
                    title = "Service : "
                    value = sc.ServiceName
                    result = title + value + vbNewLine
                    RichTextBox1.AppendText(result)
    
                    title = "Display name: "
                    value = sc.DisplayName
                    result = title + value + vbNewLine
                    RichTextBox1.AppendText(result)
    
                    Dim wmiService As New ManagementObject("Win32_Service.Name='" + sc.ServiceName + "'")
                    wmiService.Get()
                    title = "Start name: "
                    value = wmiService("StartName")
                    result = title + value + vbNewLine
                    RichTextBox1.AppendText(result)
    
                    title = "Description: "
                    value = wmiService("Description")
                    result = title + value + vbNewLine
                    RichTextBox1.AppendText(result)
    
                    result = New String("=", 60) + vbNewLine
                    RichTextBox1.AppendText(result)
                End If
            Next
        End Sub
    
    End Class

    Fig.1 Print Description on VB RichTextBox

    Please refer to the following link

    https://docs.microsoft.com/zh-tw/dotnet/api/system.serviceprocess.servicecontroller.getservices?view=netframework-4.8

    Fig.2 One of the Services

    Fig.3 Service description get by code at link page.

    Thanks and Best regards,

    E-John







    • Edited by E-John Wednesday, September 25, 2019 8:43 AM
    Wednesday, September 25, 2019 7:40 AM
  • Hi Ashidacchi,

    Add the code after Me.dgv_List(3, myRow).Value = sc.StartType

    Dim wmiService As New ManagementObject("Win32_Service.Name='" + sc.ServiceName + "'")
    wmiService.Get()
    value = wmiService("Description")
    Me.dgv_List(5, myRow).Value = value

    Thanks and Best Regards,

    E-John

    • Marked as answer by Ashidacchi Wednesday, September 25, 2019 9:49 AM
    Wednesday, September 25, 2019 8:48 AM
  • Hi E-John,

    Thank you very much.  With using WMI you taught me, I could get what I wanted.

    Best Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Wednesday, September 25, 2019 9:49 AM