stop service on remote computer

T

Torgeir Bakken (MVP)

Steve said:
What is the command syntax to stop a service on a remote
computer?

Hi

Sysinternals has a command line utility PsService that can do this:

http://www.sysinternals.com/ntw2k/freeware/pstools.shtml


ADSI can also be used for this (local and remote), here is a vbscript:

sComputer = "." ' use "." for local machine
sService = "messenger"

If StopService(sService, sComputer) Then
WScript.Echo sService & " stopped"
Else
WScript.Echo "Failed to connect to the service " & sService
End If

Function StopService(sService, sNode)

Const ADS_SERVICE_STOPPED = 1

Dim oComputer, oService
Set oComputer = GetObject("WinNT://" & sNode & ",computer")

On Error Resume Next
Set oService = oComputer.GetObject("Service", sService)
If Err.Number <> 0 Then
StopService = False
Exit Function
End If

If oService.Status <> ADS_SERVICE_STOPPED Then
oService.Stop
WScript.Sleep 1000
End If

StopService = True
End Function
 
S

Scott Losawyer

netsvc from the resource kit:
NETSVC servicename \\computername /command

or SC from the resource kit:
sc <server> [command] [service name]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top