Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

netsvc to stop service

Status
Not open for further replies.

tnayfeh

Programmer
Apr 21, 2004
39
CA
I have a command to stop a service on a remote machine.
I'm using netsvc below within a batch file.

netsvc "SERVICE NAME " \\tdsi-srv1 /stop

I get the following message "Service is pending stop on \\tdsi-srv1". Is there a way to stop this service immediately and not have it pending to stop. Same thing happens when I use the /start.

Thanks in advance,
TN
 
If you use the netsvc "SERVICE NAME " \\tdsi-srv1 /query, immediately after, you will notice that the service is indeed running. It is something to do with the netsvc command. I use this currently for one of our applications, and it doesn't give you the "full" explanation, even on a query. There are other options for you, such as:

Code:
strComputer = InputBox ("What server do you want to look at?")
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service")

For Each objService in colRunningServices 
    Wscript.Echo objService.DisplayName  & VbTab & objService.State
Next

This will tell you all the services that are on the machine, and whether they are in a started/stopped status. You can actually modify the above to have only the services that you are interested in as well.
 
If you use the netsvc "SERVICE NAME " \\tdsi-srv1 /query, immediately after, you will notice that the service is indeed stopped. It is something to do with the netsvc command. I use this currently for one of our applications, and it doesn't give you the "full" explanation, even on a query. There are other options for you, such as:

Code:
strComputer = InputBox ("What server do you want to look at?")
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service")

For Each objService in colRunningServices 
    Wscript.Echo objService.DisplayName  & VbTab & objService.State
Next

This will tell you all the services that are on the machine, and whether they are in a started/stopped status. You can actually modify the above to have only the services that you are interested in as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top