Page 1 of 1 1
Topic Options
#42194 - 2003-06-27 01:34 PM Stopping and restarting service
JohnQ Offline
Starting to like KiXtart

Registered: 2003-03-04
Posts: 171
I am using the following code to stop and restart a servcie.
code:
$Service = Getobject("WinNT://@WKSTA/Norton Antivirus Server,Service")
? "@error @Serror"
$status = $service.status
?"status is "$status
If $status = 4
$Service.stop
If @ERROR = 0
Sleep 10
$service.start
? "@error @Serror - restarting service"
EndIf
EndIf

This works fine but I would rather use a more surefire way of restarting the service without the sleep command. I would like to come up with another method to ensure that the service has indeed stopped before restarting it. Sleeping for 10 works, but I'm sure on some machines that might not be long enough for the service to shut down and then I'll get an error when it attempts to start back up - not to mention that it won't restart until the next reboot.

Any suggestions?

Top
#42195 - 2003-06-27 01:55 PM Re: Stopping and restarting service
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Just add a loop and recheck the status property until it returns "stopped". There are also stop_pending and start_pending values. Checkout some of the service related UDF's in the library.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#42196 - 2003-06-27 01:56 PM Re: Stopping and restarting service
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
after calling the stop, query the status in loop:

do sleep 0.1 until $service.status = $stopped
_________________________
!

download KiXnet

Top
#42197 - 2003-06-27 06:35 PM Re: Stopping and restarting service
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
One could also use any of the service UDFs that have been posted in the UDF Forum, like WMIService() or fADSIServiceRun().
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 581 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.057 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org