WMI Programming with Visual Basic.NET: Managing the OS - Retrieving the list of all services
(Page 2 of 6 )
Since I wanted to implement the theory stated in the previous section, I am considering an example for controlling the list of services through WMI. So, before going into the “real” controlling of services, first of all, we need to display the list of all services to the user so that he can select a service and control it. The following code fragment fetches all the services of OS and adds them to the list box.
Me.lstServices.Items.Clear()
DimsearcherAsNewManagementObjectSearcher("SELECT * FROM Win32_service ")
DimoItemsAsManagementObjectCollection = searcher.Get()
DimoItemAsManagementObject
ForEachoItemInoItems
Me.lstServices.Items.Add(oItem("DisplayName"))
Next
I don’t want to get into the details of the above fragment, because it was very clearly explained in the previous part of this series (part 2). But, make sure that we are trying to fetch all the services from the WMI class “Win32_Service”.
When you execute the above code, you should be able to see the list of all services populated into the list box as follows (Fig 1):

Next: How to know the state of a service >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee