jorge Posted August 3, 2003 Posted August 3, 2003 Hey, I'd like to make a list of all services, Via a list box i pasible, somesaid use System.ServiceProcess.ServiceController.GetServices() But don't have a clow howto! Anyone? Quote Jorge - http://www.blackdot.be/?page=apache.htm
Administrators PlausiblyDamp Posted August 3, 2003 Administrators Posted August 3, 2003 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 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
jorge Posted August 3, 2003 Author Posted August 3, 2003 (edited) Cool thanx Can i filter them? Like in the description need to be "some text"? And set the listbox to select "apache2" as default? Edited August 3, 2003 by jorge Quote Jorge - http://www.blackdot.be/?page=apache.htm
Administrators PlausiblyDamp Posted August 3, 2003 Administrators Posted August 3, 2003 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 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
jorge Posted August 3, 2003 Author Posted August 3, 2003 (edited) ok Thanx a lot:D //edit: Can i filter on description? Did not see iet anywhere. //edit2: How do i clear the listbox? Edited August 3, 2003 by jorge Quote Jorge - http://www.blackdot.be/?page=apache.htm
Administrators PlausiblyDamp Posted August 3, 2003 Administrators Posted August 3, 2003 To clear the list listbox1.Items.Clear Not too sure how you would get the description without a lot more effort though. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
jorge Posted August 4, 2003 Author Posted August 4, 2003 Thanx, Well, i'll try filtering by names then Quote Jorge - http://www.blackdot.be/?page=apache.htm
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.