Service.Stop Question or work around

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Dan from ECC
    Forum Member
    • Apr 2006
    • 25

    Service.Stop Question or work around

    I currently use this
    Code:
    Service.Stop("Myservic", "",5);
    The problem is that the service is quite complex and can has to be stopped politely. Usually this takes less then five seconds, sometimes up to 20 seconds.

    From what I understand Service.Stop does not return anything. I am currently dealing with this in a rather ugly loop. Stop the service -> check to see if the service is stopped --> if not loop for another five seconds --> and so forth until the service is reported stopped.

    Is there a better way of doing this?

    BTW, I am new to this forum and SuF 7. My searching skills are not yet what they should be.
  • TJS
    Indigo Rose Customer
    • Oct 2005
    • 524

    #2
    I had a similar issue with a service that took an abnormally long time to stop and start. The Service.Stop() action allows to to define the maximum time to wait so you'll want to set that to your worst case (20 seconds).

    It's true that the action does not return anything, but if you use the Application.GetLastError() action immediately after the stop you'll get a "0" for success or "34xx" if anything went wrong. You could then script specific logic to deal with the various potential errors.

    From SUF70 Help File
    Service Related (3400-3499)
    3401
    "An error occurred while trying to iterate the services."

    3402
    "An error occurred while trying to query the services."

    3403
    "The service could not be found."

    3404
    "The continue command failed."

    3405
    "The stop command failed."

    3406
    "The start command failed."

    3407
    "The pause command failed."

    3408
    "The delete command failed."

    3409
    "The create command failed."

    3410
    "The handle to the specified service control manager database does not have access."

    3411
    "A circular service dependency was specified."

    3412
    "The display name already exists in the service control manager database either as a service name or as another display name."

    3413
    "The handle to the specified service control manager database is invalid."

    3414
    "The specified service name is invalid."

    3415
    "A parameter that was specified is invalid."

    3416
    "The user account name specified does not exist."

    3417
    "The specified service already exists in this database."
    I'd caution against using the check>sleep>check approach because when we tried it we found (see link below) that on many systems the Application.Sleep() action consumes enough the processor to actually slow the stop process... so in essence, by waiting, you are making the stop action take longer...

    Yeah right. Who's the only one here who knows the illegal ninja moves from the government?

    ()))))))))o)))))))==============================================

    Comment

    • Dan from ECC
      Forum Member
      • Apr 2006
      • 25

      #3
      Actually, I loop and use
      Code:
       serviceisrunning = Service.Query("myservice", "")
      If serviceisrunning =1 then the service has stopped.

      Using NET STOP returns a result. I am just curious why Service.Stop does not.

      Comment

      Working...
      X