Dim flag As Boolean = False Dim item As ListViewItem For Each item In Me.ListViewServices.CheckedItems Application.DoEvents() Try Dim services As ServiceController() = ServiceController.GetServices Dim i As Integer For i = 0 To services.Length - 1 Try Do While (item.Text = services(i).ServiceName.Trim) Application.DoEvents() If (services(i).Status.ToString = "Stopped") Then MessageBox.Show("The service(s) status stopped", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk) Me.TmbRefResh_Click(sender, e) Application.DoEvents() ElseIf services(i).CanStop Then services(i).Stop() Thread.Sleep(&H3E8) item.Remove() Application.DoEvents() Else MessageBox.Show("The service(s) can't be stop", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk) End If Loop Catch obj1 As Exception End Try services(i).Refresh() Next i flag = True Catch obj2 As Exception End Try Next If Not flag Then MessageBox.Show("Please select service(s) do you want to end", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk) Me.Refresh() End If
exit
Exit Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)