Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15266

VS 2017 Starting a Service Syntax

$
0
0
Hello:

In looking at this, I want to set a service to run. I see nothing in this reference for the correct object syntax options.

https://docs.microsoft.com/en-us/dot...System_Object_


I have this code, which I really believe should work, if only I knew what the syntax was to Start or Restart the service...

Code:

service.SetPropertyValue("Name", "Running")

Code:

    Private Sub StartService(ByVal _service As String)
        Dim connection As System.Management.ConnectionOptions = New ConnectionOptions()
        connection.Username = "Administrator"
        connection.Password = "hidden"
        connection.Authority = "ntlmdomain:WACONIAMFG"
        connection.EnablePrivileges = True
        connection.Authentication = AuthenticationLevel.[Default]
        connection.Impersonation = ImpersonationLevel.Impersonate
        Dim scope As ManagementScope = New ManagementScope("\\CADSERV1\root\CIMV2", connection)
        scope.Connect()

        Dim path As ManagementPath = New ManagementPath("Win32_Service")
        Dim services As ManagementClass = New ManagementClass(scope, path, Nothing)

        For Each service As ManagementObject In services.GetInstances()
            If service.GetPropertyValue("Name") = _service Then
                service.SetPropertyValue("Name", "Running")
                Exit For

            End If

        Next

    End Sub


Viewing all articles
Browse latest Browse all 15266

Trending Articles