Jump to content
Xtreme .Net Talk

Recommended Posts

  • Administrators
Posted

just add a listbox to a form and from the components tab drop a service controller onto the form, then use this code in aform_load

 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
	Dim sc As System.ServiceProcess.ServiceController

	For Each sc In ServiceController1.GetServices
		ListBox1.Items.Add(sc.ServiceName)
	Next
End Sub

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • Administrators
Posted

The following will autoselect a particular item

 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
	Dim sc As System.ServiceProcess.ServiceController

	For Each sc In ServiceController1.GetServices
		ListBox1.Items.Add(sc.DisplayName)   'Edit: shows pretty name for service
	Next

	ListBox1.SelectedIndex = ListBox1.FindString("Indexing")    'Change "Indexing" to "Apache2" or whatever the service name is
End Sub

 

To filter you could use regular expressions if you need complex matching or for a simple one something like

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
	Dim sc As System.ServiceProcess.ServiceController

	For Each sc In ServiceController1.GetServices
		If sc.DisplayName.StartsWith("In") Then
			ListBox1.Items.Add(sc.DisplayName)
		End If
	Next

	ListBox1.SelectedIndex = ListBox1.FindString("Indexing")
End Sub

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...