Stop a Windows Service

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • João Santa Bárbara

    #1

    Stop a Windows Service

    hi all
    how can i stop a service inside it self

    i wil explain, when an erros ocurrs inside of a service, i need to stop it
    ...

    thks
    JSB


  • John Timney \(Microsoft MVP\)

    #2
    Re: Stop a Windows Service

    Something along the lines of this should stop your service.

    ServiceControll er serviceMonitor = new ServiceControll er("servicename ");
    if( serviceMonitor == ServiceControll erStatus.Runnin g )
    {
    serviceMonitor. Stop();
    }

    Regards

    John Timney
    Microsoft Regional Director
    Microsoft MVP



    "João Santa Bárbara" <joaosb@i24port ugal.com> wrote in message
    news:OSHXOL4MEH A.3348@TK2MSFTN GP09.phx.gbl...[color=blue]
    > hi all
    > how can i stop a service inside it self
    >
    > i wil explain, when an erros ocurrs inside of a service, i need to stop it
    > ..
    >
    > thks
    > JSB
    >
    >[/color]


    Comment

    • andrea catto'

      #3
      Re: Stop a Windows Service

      would it work a quick and dirty solution where you run a system command
      called "net stop" ???
      if it does...
      system("net stop myownname")

      "John Timney (Microsoft MVP)" <timneyj@despam med.com> wrote in message
      news:O9y49c7MEH A.1388@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Something along the lines of this should stop your service.
      >
      > ServiceControll er serviceMonitor = new ServiceControll er("servicename ");
      > if( serviceMonitor == ServiceControll erStatus.Runnin g )
      > {
      > serviceMonitor. Stop();
      > }
      >
      > Regards
      >
      > John Timney
      > Microsoft Regional Director
      > Microsoft MVP
      >
      >
      >
      > "João Santa Bárbara" <joaosb@i24port ugal.com> wrote in message
      > news:OSHXOL4MEH A.3348@TK2MSFTN GP09.phx.gbl...[color=green]
      > > hi all
      > > how can i stop a service inside it self
      > >
      > > i wil explain, when an erros ocurrs inside of a service, i need to stop[/color][/color]
      it[color=blue][color=green]
      > > ..
      > >
      > > thks
      > > JSB
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...