locked
check if a service is running on a remote computer. RRS feed

  • Question

  • I am using this code to try to connect to a computer/server from my desk top. but keep getting errors
    The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)


     

    Dim options As ConnectionOptions

    options =

    New ConnectionOptions()

    options.Username =

    "hq\username"

    options.Password =

    "Password"

    options.Authority =

    "kerberos:HQ.network.corp"

    options.Impersonation = ImpersonationLevel.Identify

    options.EnablePrivileges =

    True

    options.Authentication = AuthenticationLevel.Connect

     

     

     

    Dim scope As ManagementScope

     

    'scope = New ManagementScope( _

     

    ' "\\RG065006\root\cimv2")

    scope =

    New ManagementScope("\\remotecomputername\root\cimv2", options)

    scope.Connect()

     

    Dim scope As ManagementScope

     

    scope = New ManagementScope("\\RG065006\root\cimv2", options)

    scope.Connect()

     

     

     

    Try

     

    Dim mo As New Management.ManagementObject("Win32_Service.Name='RMSRELWindowsService'")

    mo.Scope = scope

     

    'tsStatus.Text = "Busy…"

    Console.WriteLine(

    "busy...")

     

    'Check if MySQL Service is installed. If not it will close the form.

     

    Try

    mo.Get()

     

    Catch ex As Exception

    Console.WriteLine(

    "Need to install MySQL Server", "MySQL Server Error")

     

    End Try

     

    'Check if the StartMode = Disabled. If so it will change it to Manual

     

    If mo("StartMode").ToString = "Disabled" Then

     

    Dim inParams, outParams As ManagementBaseObject

     

    Dim result As Integer

     

    'Get an input parameters object for this method

    inParams = mo.GetMethodParameters(

    "ChangeStartMode")

     

    'Set the StartMode to ‘Manual’

    inParams(

    "StartMode") = "Manual"

    outParams = mo.InvokeMethod(

    "ChangeStartMode", inParams, Nothing)

     

    'Check for errors 0 means the request has been accepted.

    result = Convert.ToInt32(outParams(

    "returnValue"))

     

    'Handle errors if any

     

    If result <> 0 Then

     

    Dim myErrMsg As String = ""

     

    Select Case result

     

    Case 1

    myErrMsg =

    "The request is not supported."

     

    Case 2

    myErrMsg =

    "The user did not have the necessary access."

     

    Case 3

    myErrMsg =

    "The service cannot be stopped because other services that are running are dependent on it."

     

    Case 4

    myErrMsg =

    "The requested control code is not valid, or it is unacceptable to the service."

     

    Case 5

    myErrMsg =

    "The requested control code cannot be sent to the service because the state of the service (Win32_BaseService State property) is equal to 0, 1, or 2."

     

    Case 6

    myErrMsg =

    "The service has not been started."

     

    Case 7

    myErrMsg =

    "The service did not respond to the start request in a timely fashion."

     

    Case 8

    myErrMsg =

    "Interactive process."

     

    Case 9

    myErrMsg =

    "The directory path to the service executable file was not found."

     

    Case 10

    myErrMsg =

    "The service is already running."

     

    Case 11

    myErrMsg =

    "The database to add a new service is locked."

     

    Case 12

    myErrMsg =

    "A dependency on which this service relies has been removed from the system."

     

    Case 13

    myErrMsg =

    "The service failed to find the service needed from a dependent service."

     

    Case 14

    myErrMsg =

    "The service has been disabled from the system."

     

    Case 15

    myErrMsg =

    " The service does not have the correct authentication to run on the system."

     

    Case 16

    myErrMsg =

    "This service is being removed from the system."

     

    Case 17

    myErrMsg =

    "There is no execution thread for the service."

     

    Case 18

    myErrMsg =

    "There are circular dependencies when starting the service."

     

    Case 19

    myErrMsg =

    "There is a service running under the same name."

     

    Case 20

    myErrMsg =

    "There are invalid characters in the name of the service."

     

    Case 21

    myErrMsg =

    "Invalid parameters have been passed to the service."

     

    Case 22

    myErrMsg =

    "The account which this service is to run under is either invalid or lacks the permissions to run the service."

     

    Case 23

    myErrMsg =

    "The service exists in the database of services available from the system."

     

    Case 24

    myErrMsg =

    "The service is currently paused in the system."

     

    End Select

     

    Throw New Exception("ChangeStartMode method error code " & result & ControlChars.NewLine & myErrMsg)

     

    End If

     

    End If

     

    Dim sc As New ServiceController("RMSRELWindowsService")

    sc.MachineName =

    "RG065066"

     

    Select Case sc.Status

     

    Case 1

    Console.WriteLine(

    "MySQL Server is not running, please wait…")

    sc.Start()

    Console.WriteLine(

    "Starting MySQL Server, please wait…")

    sc.WaitForStatus(ServiceControllerStatus.Running)

    Console.WriteLine(

    "Ready")

     

    Case 2

    Console.WriteLine(

    "MySQL Server is starting, please wait…")

    sc.WaitForStatus(ServiceControllerStatus.Running)

    Console.WriteLine(

    "Ready")

     

    Case 3

    Console.WriteLine(

    "MySQL Server is stopping, please wait…")

    sc.WaitForStatus(ServiceControllerStatus.Stopped)

    Console.WriteLine(

    "Starting MySQL Server, please wait…")

    sc.Start()

    sc.WaitForStatus(ServiceControllerStatus.Running)

    Console.WriteLine(

    "Ready")

     

    Case 4

    Console.WriteLine(

    "Ready")

     

    Case 5, 6, 7

    Console.WriteLine(

    "MySQL Server is stopping, please wait…")

    sc.Stop()

    sc.WaitForStatus(ServiceControllerStatus.Stopped)

    Console.WriteLine(

    "Starting MySQL Server, please wait…")

    sc.Start()

    sc.WaitForStatus(ServiceControllerStatus.Running)

    Console.WriteLine(

    "Ready")

     

    End Select

     

    Catch ex As Exception

    Console.WriteLine(Err.Description,

    "MySQL Server Error")

     

    End Try

     

     

     

    Monday, December 28, 2009 6:40 PM

Answers

  • Hello,

    Take a look at the following MSDN document, WMI Troubleshooting,
    http://msdn.microsoft.com/en-us/library/aa394603(VS.85).aspx

    0x800706BA - RPC Server Unavailable can happen when,
    1)The computer really doesn't exist 
    2)The Windows Firewall is blocking the connection

    Solution:
    Connecting to Vista: netsh advfirewall firewall set rule group="windows management instrumentation (wmi)" new enable=yes Connecting to downlevel: Allow the "Remote Administration" rule in Windows Firewall.

    Also see some other ones encounter the same error,
    http://www.eggheadcafe.com/software/aspnet/31829608/-rpc-across-domains-.aspx 


    Best regards,
    Ji Zhou


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Ji.Zhou Wednesday, January 6, 2010 3:27 AM
    Tuesday, December 29, 2009 11:15 AM

All replies

  • Monday, December 28, 2009 6:43 PM
  • no joy
    Monday, December 28, 2009 6:47 PM
  • The application is installed on my computer and i am trying to check a service on a server in england.
    Monday, December 28, 2009 6:48 PM
  • Hello,

    Take a look at the following MSDN document, WMI Troubleshooting,
    http://msdn.microsoft.com/en-us/library/aa394603(VS.85).aspx

    0x800706BA - RPC Server Unavailable can happen when,
    1)The computer really doesn't exist 
    2)The Windows Firewall is blocking the connection

    Solution:
    Connecting to Vista: netsh advfirewall firewall set rule group="windows management instrumentation (wmi)" new enable=yes Connecting to downlevel: Allow the "Remote Administration" rule in Windows Firewall.

    Also see some other ones encounter the same error,
    http://www.eggheadcafe.com/software/aspnet/31829608/-rpc-across-domains-.aspx 


    Best regards,
    Ji Zhou


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Ji.Zhou Wednesday, January 6, 2010 3:27 AM
    Tuesday, December 29, 2009 11:15 AM
  • Hello,

    Any update on this thread?

    An alternative way is developing a WCF Service application on the server side. The services can check if a specified service or process is running on the server. Then we just need to consume the WCF Service from our client to know whether service is running.

    There are two advantages to use this approach,
    1.It is better than the WMI approach because we control the whole process.
    2.Another advantage is that we can use Http protocal here. So that it can go through the FireWall.

    We can get some WCF samples from the MSDN site,
    http://msdn.microsoft.com/en-us/library/ms730936.aspx

    If you have any future questions or concerns on this, just let me know! Have a nice day, Sir!

    Best regards,
    Ji Zhou
    MSDN Subscriber Support in Forum


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Tuesday, January 5, 2010 3:00 AM