Monitoring Window services in local and remote machine
Author: DevASP Download Source Code : 653_WindowsServiceMonitor.zip
This article gives you an idea about monitoring services in local and remote machine. You can try other options like disabling the service, passing command line parameters to the service, displaying d...
This article is going to explain about monitoring the Windows Services in local and remote machines. You can communicate with existing service using ServiceController. Using ServiceController you can interact with a particular service, display list of services in remote or local machine and pass custom commands to the service. You can create ServiceController instance in several ways. In this article, I've created an instance using ServiceController class. You need to set two properties (MachineName and Name of the Service) while creating this instance through code. The default value for MachineName property is "." (Local computer).
The array arrServices will contain all the services of the local machine. To retrieve services from remote machine, pass machine name as parameter to the GetServices() method.
Once you get the instance of ServiceController you can now start, stop or pause the service. Following are the code for Start and Stop buttons. To check whether a service can stop or pause, Service Controller exposes properties such as Can Stop, Can Pause and Continue.
Steps you will do.
Start visual studio and create a new window application.
Set the following properties of the form object.
Drop a list box control on the form and set the following properties.
Drop four label controls on the form and set their following properties.
First label control.
Second label control.
Third label control.
Fourth label control.
Drop two button controls on the form and set their following properties.
First button control
Second button control
Open the code window of form and imports the following namespace.
Declare the following two global array of type string and ServiceController as below.
In the load event of the form write the following code.
In the click event of the start button write down the following code to stat the service which is currently stopped or paused.
In the click event of the button write down the following code to stop the running service.
Run your application. The list box will be loaded with the currently running services of windows. Click any of the service in the list box to see its status either it is running, paused or stop and use the button to start or stop the services.
|