WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Run Winbatch as a Service

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Sample Code to Start and Stop a Service

Keywords: 	  start and stop a service


;Stopping and starting a service

AddExtender("WWWNT34I.DLL")

sysid=""
state=0
service="Smart Card"


state = wntSvcStatus(sysid, service, 0, 2) ;get service status
If state != 1
   wntSvcControl(sysid,service , 0, 1) ;stop service
EndIf

While state != 1 ;loop until service is reported as stopped.
   TimeDelay(1)
   ErrorMode(@OFF)
      wntSvcControl(sysid, service, 0, 4) ;update status in servicemanager
   ErrorMode(@CANCEL)
   state = wntSvcStatus(sysid, service, 0, 2) ;get service status
EndWhile

Pause(service, "Service should be stopped now")


state = wntSvcStatus(sysid, service, 0, 2) ;get service status
If state !=4
    wntSvcStart(sysid, service, 0, "", "") ;start service
EndIf


While state != 4 ;loop until service starts again.
   TimeDelay(1)
   ErrorMode(@OFF)
      wntSvcControl(sysid, service, 0, 4) ;update status in servicemanager
   ErrorMode(@CANCEL)
   state = wntSvcStatus(sysid, service, 0, 2) ;get service status
EndWhile

Pause(service,"Service should be started now")



Article ID:   W14948
File Created: 2004:12:08:15:32:34
Last Updated: 2004:12:08:15:32:34