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

NT Native Commands with WinBatch

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

How to Check for a Service for a Particular Machine

Keywords:  wntServiceAt	 

Question:

I need a function to check for an active service on a particular machine (rather than listing all servers in a domain which contain a specified service.) Does WinBatch have a function to do that? I've looked at wntServiceAT.

I also want the ability to do a net start and net stop with a WB function. Ideas?

Answer:

First you can check whether the service exists,then check the status using wntSvcStatus....
MyService = "Spooler" 
AddExtender("WWWNT34I.DLL")
exist = wntSvcStatus("", MyService , 0, 0)  ; check existence Spooler service
if exist==@true
  state = wntSvcStatus("", MyService , 0, 2)  ; get the current state of the Spooler service
  Switch state
	case 1	
		Message("SERVICE_STOPPED","The service is not running.")
		break
	case 2	
		Message("SERVICE_START_PENDING","The service is starting.")
		break
	case 3	
		Message("SERVICE_STOP_PENDING","The service is stopping.")
		break
	case 4	
		Message("SERVICE_RUNNING","The service is running.")
		break
	case 5	
		Message("SERVICE_CONTINUE_PENDING","The service continue is pending.")
		break
	case 6	
		Message("SERVICE_PAUSE_PENDING","The service pause is pending.")
		break
	case 7	
		Message("SERVICE_PAUSED","The service is paused.")
		break
  EndSwitch
  
else
  message("Service checker",strcat(MyService," service does not exist"))
endif

See the Win32 network extender for the commands wntSvcStart to start a service, and wntSvcContol to stop a service.


Article ID:   W13648
Filename:   How to Check for NT Service on a Particular Machine.txt
File Created: 2001:03:01:13:25:06
Last Updated: 2001:03:01:13:25:06