start or stop services remotly

kriszty

New member
Joined
Apr 4, 2016
Messages
4
Programming Experience
10+
i want to stop and restart some services remotly.

i can start one service , but could not find a way for starting more services once

this is my code for starting remotly a service. i think it,very simple, but i can not find more info on google
all the info ion internet is for start or stop only 1 services


my code:

Imports System.ServiceProcess
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Dim services() As ServiceController = ServiceController.GetServices("computer-name")



For Each service In services
If service.ServiceName = "W32Time" Then

If (service.Status = ServiceProcess.ServiceControllerStatus.Running) Then
MessageBox.Show("Servicesrunning")
Return
Else
MsgBox("service is starting")
service.Start()
End If
End If
Next

End Sub
End Class
 
after some trying myself , i managed it

Imports System.ServiceProcess
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim services As ServiceController()
services = ServiceController.GetServices("patrick-hp")
Dim i As Integer

ListBox1.Items.Clear()
For i = 0 To services.Length - 1
ListBox1.Items.Add(services(i).ServiceName)

If ListBox1.Items(i).Contains("TeamViewer") Then
MsgBox("found teamviewer")
services(i).Start()
End If

If ListBox1.Items(i).Contains("W32Time") Then
MsgBox("found w32time")
services(i).Start()
End If



Next
End Sub


End Class
 
Back
Top