Skip to main content

Resume Service on Remote Machine

What is Windows Service
Windows Service is a background process that performs certain task. We can perform various methods on service like start,stop,pause or resume on local or remote machine.
In this article you will perform resume methods on service using VB.Net. Here you can use "ResumeService" Function which is given below. Using this function you can perform this action on local or remote machine according to your need.

Private Sub ResumeService(ByVal strComputer As String, ByVal strService As String)

        Try

            Dim objWMIService, colServiceList, objService, errReturn, objSWbemLocator

            objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

            If (strComputer = Environment.MachineName.ToString) Then

                objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\cimv2")
            Else
                objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\cimv2", UserName, Password)
            End If

            objWMIService.Security_.ImpersonationLevel = 3

            colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where DisplayName='" & strService & "'")

            For Each objService In colServiceList
                errReturn = objService.ResumeService()
            Next

            If (errReturn = 0) Then
                colServiceList = objWMIService.ExecQuery("Associators of " & "{Win32_Service.DisplayName='" & strService & "'} Where " & "AssocClass=Win32_DependentService " & "Role=Dependent")

                For Each objService In colServiceList
                    objService.ResumeService()
                Next

            End If

            MessageBox.Show("Service Successfully Resumed.", "Service Manager", MessageBoxButtons.OK, MessageBoxIcon.Information)

        Catch ex As Exception
            MessageBox.Show(ex.Message, "Service Manager", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

End Sub

Step-By-Step
  • Create object for connecting server either local or remote.
  • For Remote connection we use admin credential.
  • Use WMI Win32_Service for selecting particular service on desired machine.
  • Use For Loop for resuming that service.
  • Next step will be for resuming dependent services.
  • Successfully done.

Popular posts from this blog

Ping Network Computer in VB.Net

"Ping" is very basic utility for every network programmer. Here we will discuss ping a computer in Network using VB.Net. We have two methods for pinging a computer. Method 1: Here we will use VB.Net NetworkInformation NameSpace. Public Sub PingStatus(ByVal strComputer As String) Dim pingSender As Ping = New Ping() Dim options As PingOptions = New PingOptions() options.DontFragment = True 'Create a buffer of 32 bytes of data to be transmitted Dim data As String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" Dim buffer As Byte() = Encoding.ASCII.GetBytes(data) Dim timeout As Integer = 120 Dim reply As PingReply = pingSender.Send(strComputer, timeout, buffer, options) If (reply.Status = IPStatus.Success) Then MessageBox.Show("Ping Successed.") Else MessageBox.Show("Ping Faild.") End If End Sub Method 2: Here we are using .Net inbuil

GridView Paging and Sorting

Introduction Paging and Sorting are most commonly used features of ASP.Net GridView. And it is very easy to implement in GridView with small lines of code. Here I am going to demonstrate how to use Paging and Sorting in GridView for better use of data display.